CARLA
Loading...
Searching...
No Matches
ActorROS2Handler.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "ActorROS2Handler.h"
11
13{
14 if (!_Actor) return;
15
16 ACarlaWheeledVehicle *Vehicle = Cast<ACarlaWheeledVehicle>(_Actor);
17 if (!Vehicle) return;
18
19 // setup control values
20 FVehicleControl NewControl;
21 NewControl.Throttle = Source.throttle;
22 NewControl.Steer = Source.steer;
23 NewControl.Brake = Source.brake;
24 NewControl.bHandBrake = Source.hand_brake;
25 NewControl.bReverse = Source.reverse;
26 NewControl.bManualGearShift = Source.manual_gear_shift;
27 NewControl.Gear = Source.gear;
28
29 Vehicle->ApplyVehicleControl(NewControl, EVehicleInputPriority::User);
30}
31
33{
34 if (!_Actor) return;
35
36 ACarlaWheeledVehicle *Vehicle = Cast<ACarlaWheeledVehicle>(_Actor);
37 if (!Vehicle) return;
38
39 FVehicleAckermannControl NewControl;
40 NewControl.Steer = Source.steer;
41 NewControl.SteerSpeed = Source.steer_speed;
42 NewControl.Speed = Source.speed;
43 NewControl.Acceleration = Source.acceleration;
44 NewControl.Jerk = Source.jerk;
45
46 Vehicle->ApplyVehicleAckermannControl(NewControl, EVehicleInputPriority::User);
47}
48
50{
51 if (!IsValid(_Actor)) return;
52
53 ACarlaWheeledVehicle *Vehicle = Cast<ACarlaWheeledVehicle>(_Actor);
54 if (!IsValid(Vehicle)) return;
55
56 // /control/command/control_cmd: use acceleration [m/s^2] + steering for acceleration control
57 Vehicle->ApplyVehicleAccelerationControl(Source.acceleration, Source.steer, Source.steer_speed);
58}
59
61{
62 if (!_Actor) return;
63
64 ACarlaWheeledVehicle *Vehicle = Cast<ACarlaWheeledVehicle>(_Actor);
65 if (!Vehicle) return;
66
67 Vehicle->PrintROS2Message(Message.message);
68
69 // FString ROSMessage = Message.message;
70 // UE_LOG(LogCarla, Warning, TEXT("ROS2 Message received: %s"), *ROSMessage);
71}
72
74{
75 if (!IsValid(Actor)) return false;
76
77 ACarlaWheeledVehicle * const Vehicle = Cast<ACarlaWheeledVehicle>(Actor);
78 if (!IsValid(Vehicle)) return false;
79
80 auto VehiclePhysicsControl = Vehicle->GetVehiclePhysicsControl();
81
82 /// @note Flatten steering curve to be always 1.0 to properly map wheel angle to steering at all speeds
83 VehiclePhysicsControl.SteeringCurve.Reset();
84 VehiclePhysicsControl.SteeringCurve.AddKey(0.f, 1.f);
85 VehiclePhysicsControl.SteeringCurve.AddKey(120.f, 1.f);
86
87 Vehicle->ApplyVehiclePhysicsControl(VehiclePhysicsControl);
88 UE_LOG(LogCarla, Log, TEXT("Resetting SteeringCurve!"));
89
90 return true;
91}
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
Base class for CARLA wheeled vehicles.
void operator()(carla::ros2::VehicleControl &Source)
static bool FlattenSteeringCurve(AActor *Actor)
Flatten the vehicle's steering curve to 1.0 at all speeds so the Autoware steering command maps 1:1 t...
Control decoded from Autoware's /control/command/control_cmd: longitudinal acceleration [m/s^2] + ste...