@@ -40,6 +40,8 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
40
40
// for steering steer controller
41
41
use_steer_ff_ = declare_parameter<bool >(" use_steer_ff" );
42
42
use_steer_fb_ = declare_parameter<bool >(" use_steer_fb" );
43
+ use_vehicle_adaptor_ = declare_parameter<bool >(" use_vehicle_adaptor" , false );
44
+
43
45
if (convert_accel_cmd_) {
44
46
if (!accel_map_.readAccelMapFromCSV (csv_path_accel_map, true )) {
45
47
throw std::invalid_argument (" Accel map is invalid." );
@@ -121,10 +123,11 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(
121
123
122
124
void RawVehicleCommandConverterNode::publishActuationCmd ()
123
125
{
124
- if (!current_twist_ptr_ || !control_cmd_ptr_ || !current_steer_ptr_) {
126
+ /* check if all necessary data is available */
127
+ if (!current_odometry_ || !control_cmd_ptr_ || !current_steer_ptr_) {
125
128
RCLCPP_WARN_EXPRESSION (
126
129
get_logger (), is_debugging_, " some pointers are null: %s, %s, %s" ,
127
- !current_twist_ptr_ ? " twist " : " " , !control_cmd_ptr_ ? " cmd" : " " ,
130
+ !current_odometry_ ? " odometry " : " " , !control_cmd_ptr_ ? " cmd" : " " ,
128
131
!current_steer_ptr_ ? " steer" : " " );
129
132
return ;
130
133
}
@@ -136,14 +139,33 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
136
139
}
137
140
}
138
141
142
+ const auto current_accel = sub_accel_.takeData ();
143
+ const auto current_operation_mode = sub_operation_mode_.takeData ();
144
+ if (use_vehicle_adaptor_) {
145
+ if (!current_accel || !current_operation_mode) {
146
+ RCLCPP_WARN_EXPRESSION (
147
+ get_logger (), is_debugging_, " some pointers are null: %s, %s" ,
148
+ !current_accel ? " accel" : " " , !current_operation_mode ? " operation_mode" : " " );
149
+ return ;
150
+ }
151
+ }
152
+
153
+ /* compensate control command if vehicle adaptor is enabled */
154
+ const Control control_cmd = use_vehicle_adaptor_
155
+ ? vehicle_adaptor_.compensate (
156
+ *control_cmd_ptr_, *current_odometry_, *current_accel,
157
+ *current_steer_ptr_, *current_operation_mode)
158
+ : *control_cmd_ptr_;
159
+
160
+ /* calculate actuation command */
139
161
double desired_accel_cmd = 0.0 ;
140
162
double desired_brake_cmd = 0.0 ;
141
163
double desired_steer_cmd = 0.0 ;
142
164
ActuationCommandStamped actuation_cmd;
143
- const double acc = control_cmd_ptr_-> longitudinal .acceleration ;
144
- const double vel = current_twist_ptr_-> twist .linear .x ;
145
- const double steer = control_cmd_ptr_-> lateral .steering_tire_angle ;
146
- const double steer_rate = control_cmd_ptr_-> lateral .steering_tire_rotation_rate ;
165
+ const double acc = control_cmd. longitudinal .acceleration ;
166
+ const double vel = current_odometry_-> twist . twist .linear .x ;
167
+ const double steer = control_cmd. lateral .steering_tire_angle ;
168
+ const double steer_rate = control_cmd. lateral .steering_tire_rotation_rate ;
147
169
bool accel_cmd_is_zero = true ;
148
170
if (convert_accel_cmd_) {
149
171
desired_accel_cmd = calculateAccelMap (vel, acc, accel_cmd_is_zero);
@@ -173,7 +195,7 @@ void RawVehicleCommandConverterNode::publishActuationCmd()
173
195
desired_steer_cmd = calculateSteerFromMap (vel, steer, steer_rate);
174
196
}
175
197
actuation_cmd.header .frame_id = " base_link" ;
176
- actuation_cmd.header .stamp = control_cmd_ptr_-> stamp ;
198
+ actuation_cmd.header .stamp = control_cmd. stamp ;
177
199
actuation_cmd.actuation .accel_cmd = desired_accel_cmd;
178
200
actuation_cmd.actuation .brake_cmd = desired_brake_cmd;
179
201
actuation_cmd.actuation .steer_cmd = desired_steer_cmd;
@@ -252,12 +274,7 @@ double RawVehicleCommandConverterNode::calculateBrakeMap(
252
274
253
275
void RawVehicleCommandConverterNode::onControlCmd (const Control::ConstSharedPtr msg)
254
276
{
255
- const auto odometry_msg = sub_odometry_.takeData ();
256
- if (odometry_msg) {
257
- current_twist_ptr_ = std::make_unique<TwistStamped>();
258
- current_twist_ptr_->header = odometry_msg->header ;
259
- current_twist_ptr_->twist = odometry_msg->twist .twist ;
260
- }
277
+ current_odometry_ = sub_odometry_.takeData ();
261
278
control_cmd_ptr_ = msg;
262
279
publishActuationCmd ();
263
280
}
@@ -277,14 +294,11 @@ void RawVehicleCommandConverterNode::onActuationStatus(
277
294
}
278
295
279
296
// calculate steering status from actuation status
280
- const auto odometry_msg = sub_odometry_.takeData ();
281
- if (odometry_msg ) {
297
+ current_odometry_ = sub_odometry_.takeData ();
298
+ if (current_odometry_ ) {
282
299
if (convert_steer_cmd_method_.value () == " vgr" ) {
283
- current_twist_ptr_ = std::make_unique<TwistStamped>();
284
- current_twist_ptr_->header = odometry_msg->header ;
285
- current_twist_ptr_->twist = odometry_msg->twist .twist ;
286
300
current_steer_ptr_ = std::make_unique<double >(vgr_.calculateSteeringTireState (
287
- current_twist_ptr_-> twist .linear .x , actuation_status_ptr_->status .steer_status ));
301
+ current_odometry_-> twist . twist .linear .x , actuation_status_ptr_->status .steer_status ));
288
302
Steering steering_msg{};
289
303
steering_msg.steering_tire_angle = *current_steer_ptr_;
290
304
pub_steering_status_->publish (steering_msg);
0 commit comments