40 #define ROS_LOG_ONCE_ID(id, level, name, ...) \
43 ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
44 static std::map<int, bool> map; \
45 bool &hit = map[id]; \
46 if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \
49 ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
52 #define ROS_DEBUG_ONCE_ID(id, ...) ROS_LOG_ONCE_ID(id, ::ros::console::levels::Debug, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
53 #define ROS_INFO_ONCE_ID(id, ...) ROS_LOG_ONCE_ID(id, ::ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
54 #define ROS_WARN_ONCE_ID(id, ...) ROS_LOG_ONCE_ID(id, ::ros::console::levels::Warn, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
55 #define ROS_ERROR_ONCE_ID(id, ...) ROS_LOG_ONCE_ID(id, ::ros::console::levels::Error, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
56 #define ROS_FATAL_ONCE_ID(id, ...) ROS_LOG_ONCE_ID(id, ::ros::console::levels::Fatal, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
177 if (!msg->is_rtr && !msg->is_error && !msg->is_extended) {
186 dbw_polaris_msgs::BrakeReport out;
187 out.header.stamp = msg->header.stamp;
190 out.torque_input = ptr->
PI;
191 out.torque_cmd = ptr->
PC;
192 out.torque_output = ptr->
PO;
196 out.enabled = ptr->
ENABLED ? true :
false;
197 out.override = ptr->
OVERRIDE ? true :
false;
198 out.driver = ptr->
DRIVER ? true :
false;
199 out.watchdog_counter.source = ptr->
WDCSRC;
200 out.watchdog_braking = ptr->
WDCBRK ? true :
false;
201 out.fault_wdc = ptr->
FLTWDC ? true :
false;
202 out.fault_ch1 = ptr->
FLT1 ? true :
false;
203 out.fault_ch2 = ptr->
FLT2 ? true :
false;
204 out.fault_power = ptr->
FLTPWR ? true :
false;
205 out.timeout = ptr->
TMOUT ? true :
false;
209 ptr->
FLT1 ?
"true, " :
"false,",
210 ptr->
FLT2 ?
"true, " :
"false,",
211 ptr->
FLTPWR ?
"true" :
"false");
223 dbw_polaris_msgs::ThrottleReport out;
224 out.header.stamp = msg->header.stamp;
225 out.pedal_input = (float)ptr->
PI / UINT16_MAX;
226 out.pedal_cmd = (
float)ptr->
PC / UINT16_MAX;
227 out.pedal_output = (float)ptr->
PO / UINT16_MAX;
228 out.enabled = ptr->
ENABLED ?
true :
false;
229 out.override = ptr->
OVERRIDE ?
true :
false;
230 out.driver = ptr->
DRIVER ?
true :
false;
231 out.watchdog_counter.source = ptr->
WDCSRC;
232 out.fault_wdc = ptr->
FLTWDC ?
true :
false;
233 out.fault_ch1 = ptr->
FLT1 ?
true :
false;
234 out.fault_ch2 = ptr->
FLT2 ?
true :
false;
235 out.fault_power = ptr->
FLTPWR ?
true :
false;
236 out.timeout = ptr->
TMOUT ?
true :
false;
240 ptr->
FLT1 ?
"true, " :
"false,",
241 ptr->
FLT2 ?
"true, " :
"false,",
242 ptr->
FLTPWR ?
"true" :
"false");
255 dbw_polaris_msgs::SteeringReport out;
256 out.header.stamp = msg->header.stamp;
257 if ((uint16_t)ptr->
ANGLE == 0x8000) {
258 out.steering_wheel_angle = NAN;
260 out.steering_wheel_angle = (float)ptr->
ANGLE * (
float)(0.1 * M_PI / 180);
262 out.steering_wheel_cmd_type = ptr->
TMODE ? dbw_polaris_msgs::SteeringReport::CMD_TORQUE : dbw_polaris_msgs::SteeringReport::CMD_ANGLE;
263 if ((uint16_t)ptr->
CMD == 0xC000) {
264 out.steering_wheel_cmd = NAN;
265 }
else if (out.steering_wheel_cmd_type == dbw_polaris_msgs::SteeringReport::CMD_ANGLE) {
266 out.steering_wheel_cmd = (float)ptr->
CMD * (
float)(0.1 * M_PI / 180);
268 out.steering_wheel_cmd = (float)ptr->
CMD / 128.0f;
270 if ((uint8_t)ptr->
TORQUE == 0x80) {
271 out.steering_wheel_torque = NAN;
273 out.steering_wheel_torque = (float)ptr->
TORQUE * (
float)0.0625;
275 if ((uint16_t)ptr->
VEH_VEL == 0x8000) {
278 out.speed = (float)ptr->
VEH_VEL * (
float)(0.01 / 3.6);
280 out.enabled = ptr->
ENABLED ? true :
false;
281 out.override = ptr->
OVERRIDE ? true :
false;
282 out.fault_wdc = ptr->
FLTWDC ? true :
false;
283 out.fault_bus1 = ptr->
FLTBUS1 ? true :
false;
284 out.fault_bus2 = ptr->
FLTBUS2 ? true :
false;
285 out.fault_calibration = ptr->
FLTCAL ? true :
false;
286 out.fault_power = ptr->
FLTPWR ? true :
false;
287 out.timeout = ptr->
TMOUT ? true :
false;
289 geometry_msgs::TwistStamped twist;
290 twist.header.stamp = out.header.stamp;
292 twist.twist.linear.x = out.speed;
298 ptr->
FLTBUS1 ?
"true, " :
"false,",
299 ptr->
FLTBUS2 ?
"true, " :
"false,",
300 ptr->
FLTPWR ?
"true" :
"false");
302 ROS_WARN_THROTTLE(5.0,
"Steering fault. Too many calibrations stored. Reset need to continue");
305 ROS_WARN_THROTTLE(5.0,
"Steering calibration fault. Press the two steering multiplier buttons at the same "
306 "time to set the center offset when the wheel is straight. For a more exact "
307 "calibration set the SteeringCal and SteeringCal offset parameters using DbwConfig.");
316 dbw_polaris_msgs::GearReport out;
317 out.header.stamp = msg->header.stamp;
318 out.state.gear = ptr->
STATE;
319 out.cmd.gear = ptr->
CMD;
320 out.override = ptr->
OVERRIDE ? true :
false;
321 out.fault_bus = ptr->
FLTBUS ? true :
false;
322 out.reject.value = ptr->
REJECT;
323 if (out.reject.value == dbw_polaris_msgs::GearReject::NONE) {
327 switch (out.reject.value) {
328 case dbw_polaris_msgs::GearReject::SHIFT_IN_PROGRESS:
329 ROS_WARN(
"Gear shift rejected: Shift in progress");
331 case dbw_polaris_msgs::GearReject::OVERRIDE:
332 ROS_WARN(
"Gear shift rejected: Override on brake, throttle, or steering");
334 case dbw_polaris_msgs::GearReject::NEUTRAL:
335 ROS_WARN(
"Gear shift rejected: Manually shift to neutral before auto-shift");
337 case dbw_polaris_msgs::GearReject::VEHICLE:
338 ROS_WARN(
"Gear shift rejected: Rejected by vehicle, try pressing the brakes");
340 case dbw_polaris_msgs::GearReject::UNSUPPORTED:
341 ROS_WARN(
"Gear shift rejected: Unsupported gear command");
343 case dbw_polaris_msgs::GearReject::FAULT:
344 ROS_WARN(
"Gear shift rejected: System in fault state");
361 ROS_WARN_ONCE_ID(module,
"Licensing: %s one or more features licensed as a counted trial. Visit https://www.dataspeedinc.com/products/maintenance-subscription/ to request a full license.", str_m);
364 ROS_WARN_ONCE_ID(module,
"Licensing: %s one or more feature licenses expired due to the firmware build date", str_m);
366 }
else if (module ==
M_STEER) {
386 ROS_INFO(
"Licensing: %s license string date: %s", str_m,
ldate_.c_str());
389 ROS_INFO_ONCE(
"Licensing: %s MAC: %02X:%02X:%02X:%02X:%02X:%02X", str_m,
390 ptr->
mac.addr0, ptr->
mac.addr1,
391 ptr->
mac.addr2, ptr->
mac.addr3,
392 ptr->
mac.addr4, ptr->
mac.addr5);
394 std::string &bdate =
bdate_[module];
395 if (bdate.size() == 0) {
396 bdate.push_back(ptr->
bdate0.date0);
397 bdate.push_back(ptr->
bdate0.date1);
398 bdate.push_back(ptr->
bdate0.date2);
399 bdate.push_back(ptr->
bdate0.date3);
400 bdate.push_back(ptr->
bdate0.date4);
401 bdate.push_back(ptr->
bdate0.date5);
404 std::string &bdate =
bdate_[module];
405 if (bdate.size() == 6) {
406 bdate.push_back(ptr->
bdate1.date6);
407 bdate.push_back(ptr->
bdate1.date7);
408 bdate.push_back(ptr->
bdate1.date8);
409 bdate.push_back(ptr->
bdate1.date9);
410 ROS_INFO(
"Licensing: %s firmware build date: %s", str_m, bdate.c_str());
413 if (
vin_.size() == 0) {
422 if (
vin_.size() == 6) {
431 if (
vin_.size() == 12) {
437 std_msgs::String msg; msg.data =
vin_;
441 }
else if ((LIC_MUX_F0 <= ptr->mux) && (ptr->
mux <=
LIC_MUX_F7)) {
442 constexpr std::array<const char*, 8>
NAME = {
"BASE",
"CONTROL",
"SENSORS",
"",
"",
"",
"",
""};
443 constexpr std::array<bool, 8> WARN = {
true,
true,
true,
false,
true,
true,
true,
true};
445 const int id = module *
NAME.size() + i;
446 const std::string name = strcmp(
NAME[i],
"") ?
NAME[i] : std::string(1,
'0' + i);
448 ROS_INFO_ONCE_ID(
id,
"Licensing: %s feature '%s' enabled%s", str_m, name.c_str(), ptr->
license.trial ?
" as a counted trial" :
"");
449 }
else if (ptr->
ready && !WARN[i]) {
450 ROS_INFO_ONCE_ID(
id,
"Licensing: %s feature '%s' not licensed.", str_m, name.c_str());
451 }
else if (ptr->
ready) {
452 ROS_WARN_ONCE_ID(
id,
"Licensing: %s feature '%s' not licensed. Visit https://www.dataspeedinc.com/products/maintenance-subscription/ to request a license.", str_m, name.c_str());
455 ROS_INFO_ONCE(
"Licensing: Feature '%s' trials used: %u, remaining: %u", name.c_str(),
471 if (latest.
valid()) {
474 ROS_WARN(
"Detected %s %s firmware version %u.%u.%u, which is unsupported. Platform: 0x%02X, Module: %u", str_p, str_m,
477 if (version < latest) {
478 ROS_WARN(
"Firmware %s %s has old version %u.%u.%u, updating to %u.%u.%u is suggested.", str_p, str_m,
479 version.v.major(), version.v.minor(), version.v.build(),
488 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Brake. Id: 0x%03X",
ID_BRAKE_CMD);
492 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Throttle. Id: 0x%03X",
ID_THROTTLE_CMD);
496 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Steering. Id: 0x%03X",
ID_STEERING_CMD);
500 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Shifting. Id: 0x%03X",
ID_GEAR_CMD);
503 case 0x100 ... 0x103:
504 case 0x6C0 ... 0x6C5:
505 ROS_WARN_ONCE_ID(msg->id,
"Received unsupported CAN ID %03X from next-generation drive-by-wire system (DBW2)"
506 "\nUse the ROS2 ds_dbw_can package instead", msg->id);
511 ROS_INFO(
"ena: %s, clr: %s, brake: %s, throttle: %s, steering: %s, gear: %s",
513 clear() ?
"true " :
"false",
529 sensor_msgs::Imu out;
530 out.header.stamp = msgs[0]->header.stamp;
532 out.orientation_covariance[0] = -1;
533 if ((uint16_t)ptr_accel->
accel_long == 0x8000) {
534 out.linear_acceleration.x = NAN;
536 out.linear_acceleration.x = (double)ptr_accel->
accel_long * 0.01;
538 if ((uint16_t)ptr_accel->
accel_lat == 0x8000) {
539 out.linear_acceleration.y = NAN;
541 out.linear_acceleration.y = (double)ptr_accel->
accel_lat * -0.01;
543 if ((uint16_t)ptr_accel->
accel_vert == 0x8000) {
544 out.linear_acceleration.z = NAN;
546 out.linear_acceleration.z = (double)ptr_accel->
accel_vert * -0.01;
548 if ((uint16_t)ptr_gyro->gyro_roll == 0x8000) {
549 out.angular_velocity.x = NAN;
551 out.angular_velocity.x = (double)ptr_gyro->gyro_roll * 0.0002;
553 if ((uint16_t)ptr_gyro->gyro_pitch == 0x8000) {
554 out.angular_velocity.y = NAN;
556 out.angular_velocity.y = (double)ptr_gyro->gyro_pitch * 0.0002;
558 if ((uint16_t)ptr_gyro->gyro_yaw == 0x8000) {
559 out.angular_velocity.z = NAN;
561 out.angular_velocity.z = (double)ptr_gyro->gyro_yaw * 0.0002;
566 ROS_INFO(
"Time: %u.%u, %u.%u, delta: %fms",
567 msgs[0]->
header.stamp.sec, msgs[0]->header.stamp.nsec,
568 msgs[1]->header.stamp.sec, msgs[1]->header.stamp.nsec,
569 labs((msgs[1]->
header.stamp - msgs[0]->header.stamp).toNSec()) / 1000000.0);
577 out.is_extended =
false;
580 memset(ptr, 0x00,
sizeof(*ptr));
581 switch (msg->pedal_cmd_type) {
582 case dbw_polaris_msgs::BrakeCmd::CMD_NONE:
584 case dbw_polaris_msgs::BrakeCmd::CMD_PERCENT:
585 ptr->
CMD_TYPE = dbw_polaris_msgs::BrakeCmd::CMD_PERCENT;
586 ptr->
PCMD = std::clamp<float>(msg->pedal_cmd * UINT16_MAX, 0, UINT16_MAX);
588 case dbw_polaris_msgs::BrakeCmd::CMD_TORQUE:
589 ptr->
CMD_TYPE = dbw_polaris_msgs::BrakeCmd::CMD_TORQUE;
590 ptr->
PCMD = std::clamp<float>(msg->pedal_cmd, 0, UINT16_MAX);
592 case dbw_polaris_msgs::BrakeCmd::CMD_TORQUE_RQ:
593 ptr->
CMD_TYPE = dbw_polaris_msgs::BrakeCmd::CMD_TORQUE_RQ;
594 ptr->
PCMD = std::clamp<float>(msg->pedal_cmd, 0, UINT16_MAX);
597 ROS_WARN(
"Unknown brake command type: %u", msg->pedal_cmd_type);
600 if (
enabled() && msg->enable) {
603 if (
clear() || msg->clear) {
609 ptr->
COUNT = msg->count;
617 out.is_extended =
false;
620 memset(ptr, 0x00,
sizeof(*ptr));
623 switch (msg->pedal_cmd_type) {
624 case dbw_polaris_msgs::ThrottleCmd::CMD_NONE:
626 case dbw_polaris_msgs::ThrottleCmd::CMD_PEDAL:
627 ptr->
CMD_TYPE = dbw_polaris_msgs::ThrottleCmd::CMD_PEDAL;
628 cmd = msg->pedal_cmd;
630 case dbw_polaris_msgs::ThrottleCmd::CMD_PERCENT:
632 ptr->
CMD_TYPE = dbw_polaris_msgs::ThrottleCmd::CMD_PERCENT;
633 cmd = msg->pedal_cmd;
635 ptr->
CMD_TYPE = dbw_polaris_msgs::ThrottleCmd::CMD_PEDAL;
640 ROS_WARN(
"Unknown throttle command type: %u", msg->pedal_cmd_type);
643 ptr->
PCMD = std::clamp<float>(
cmd * UINT16_MAX, 0, UINT16_MAX);
644 if (
enabled() && msg->enable) {
647 if (
clear() || msg->clear) {
653 ptr->
COUNT = msg->count;
661 out.is_extended =
false;
664 memset(ptr, 0x00,
sizeof(*ptr));
665 switch (msg->cmd_type) {
666 case dbw_polaris_msgs::SteeringCmd::CMD_ANGLE:
667 ptr->
SCMD = std::clamp<float>(msg->steering_wheel_angle_cmd * (
float)(180 / M_PI * 10), -INT16_MAX, INT16_MAX);
668 if (fabsf(msg->steering_wheel_angle_velocity) > 0) {
669 ptr->
SVEL = std::clamp<float>(roundf(fabsf(msg->steering_wheel_angle_velocity) * (
float)(180 / M_PI / 4)), 1, 254);
671 ptr->
CMD_TYPE = dbw_polaris_msgs::SteeringCmd::CMD_ANGLE;
673 case dbw_polaris_msgs::SteeringCmd::CMD_TORQUE:
674 ptr->
SCMD = std::clamp<float>(msg->steering_wheel_torque_cmd * 128, -INT16_MAX, INT16_MAX);
675 ptr->
CMD_TYPE = dbw_polaris_msgs::SteeringCmd::CMD_TORQUE;
678 ROS_WARN(
"Unknown steering command type: %u", msg->cmd_type);
681 if (
enabled() && msg->enable) {
684 if (
clear() || msg->clear) {
690 if (msg->calibrate) {
699 ptr->
COUNT = msg->count;
707 out.is_extended =
false;
710 memset(ptr, 0x00,
sizeof(*ptr));
712 ptr->
GCMD = msg->cmd.gear;
714 if (
clear() || msg->clear) {
729 out.is_extended =
false;
740 if (change || force) {
753 ROS_WARN(
"DBW system enable status changed unexpectedly");
759 out.is_extended =
false;
764 memset(out.data.elems, 0x00, 8);
772 memset(out.data.elems, 0x00, 8);
780 memset(out.data.elems, 0x00, 8);
788 memset(out.data.elems, 0x00, 8);
800 ROS_WARN(
"DBW system not enabled. Steering calibration fault.");
803 ROS_WARN(
"DBW system not enabled. Braking fault.");
806 ROS_WARN(
"DBW system not enabled. Throttle fault.");
809 ROS_WARN(
"DBW system not enabled. Steering fault.");
812 ROS_WARN(
"DBW system not enabled. Watchdog fault.");
819 ROS_INFO(
"DBW system enable requested. Waiting for ready.");
839 ROS_WARN(
"DBW system disabled. Cancel button pressed.");
849 if (en &&
override) {
855 ROS_WARN(
"DBW system disabled. Driver override on brake/throttle pedal.");
868 if (en &&
override) {
874 ROS_WARN(
"DBW system disabled. Driver override on brake/throttle pedal.");
887 if (en &&
override) {
893 ROS_WARN(
"DBW system disabled. Driver override on steering wheel.");
903 if (en &&
override) {
909 ROS_WARN(
"DBW system disabled. Driver override on shifter.");
919 ROS_WARN(
"Brake subsystem disabled after 100ms command timeout");
928 ROS_WARN(
"Throttle subsystem disabled after 100ms command timeout");
937 ROS_WARN(
"Steering subsystem disabled after 100ms command timeout");
952 ROS_ERROR(
"DBW system disabled. Braking fault.");
968 ROS_ERROR(
"DBW system disabled. Throttle fault.");
984 ROS_ERROR(
"DBW system disabled. Steering fault.");
1000 ROS_ERROR(
"DBW system disabled. Steering calibration fault.");
1016 ROS_ERROR(
"DBW system disabled. Watchdog fault.");
1022 ROS_WARN(
"Watchdog event: Alerting driver and applying brakes.");
1024 ROS_INFO(
"Watchdog event: Driver has successfully taken control.");
1028 case dbw_polaris_msgs::WatchdogCounter::OTHER_BRAKE:
1029 ROS_WARN(
"Watchdog event: Fault determined by brake controller");
1031 case dbw_polaris_msgs::WatchdogCounter::OTHER_THROTTLE:
1032 ROS_WARN(
"Watchdog event: Fault determined by throttle controller");
1034 case dbw_polaris_msgs::WatchdogCounter::OTHER_STEERING:
1035 ROS_WARN(
"Watchdog event: Fault determined by steering controller");
1037 case dbw_polaris_msgs::WatchdogCounter::BRAKE_COUNTER:
1038 ROS_WARN(
"Watchdog event: Brake command counter failed to increment");
1040 case dbw_polaris_msgs::WatchdogCounter::BRAKE_DISABLED:
1041 ROS_WARN(
"Watchdog event: Brake transition to disabled while in gear or moving");
1043 case dbw_polaris_msgs::WatchdogCounter::BRAKE_COMMAND:
1044 ROS_WARN(
"Watchdog event: Brake command timeout after 100ms");
1046 case dbw_polaris_msgs::WatchdogCounter::BRAKE_REPORT:
1047 ROS_WARN(
"Watchdog event: Brake report timeout after 100ms");
1049 case dbw_polaris_msgs::WatchdogCounter::THROTTLE_COUNTER:
1050 ROS_WARN(
"Watchdog event: Throttle command counter failed to increment");
1052 case dbw_polaris_msgs::WatchdogCounter::THROTTLE_DISABLED:
1053 ROS_WARN(
"Watchdog event: Throttle transition to disabled while in gear or moving");
1055 case dbw_polaris_msgs::WatchdogCounter::THROTTLE_COMMAND:
1056 ROS_WARN(
"Watchdog event: Throttle command timeout after 100ms");
1058 case dbw_polaris_msgs::WatchdogCounter::THROTTLE_REPORT:
1059 ROS_WARN(
"Watchdog event: Throttle report timeout after 100ms");
1061 case dbw_polaris_msgs::WatchdogCounter::STEERING_COUNTER:
1062 ROS_WARN(
"Watchdog event: Steering command counter failed to increment");
1064 case dbw_polaris_msgs::WatchdogCounter::STEERING_DISABLED:
1065 ROS_WARN(
"Watchdog event: Steering transition to disabled while in gear or moving");
1067 case dbw_polaris_msgs::WatchdogCounter::STEERING_COMMAND:
1068 ROS_WARN(
"Watchdog event: Steering command timeout after 100ms");
1070 case dbw_polaris_msgs::WatchdogCounter::STEERING_REPORT:
1071 ROS_WARN(
"Watchdog event: Steering report timeout after 100ms");
1075 }
else if (!
fault) {
1080 ROS_WARN_THROTTLE(2.0,
"Watchdog event: Press left OK button on the steering wheel or cycle power to clear event.");
1090 double dt = (stamp -
joint_state_.header.stamp).toSec();
1092 if (std::isfinite(steering->steering_wheel_angle)) {
1095 const double r = L / tan(steering->steering_wheel_angle /
steering_ratio_);
1099 if (std::isfinite(steering->speed)) {