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