00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "DbwNode.h"
00036 #include <dbw_fca_can/dispatch.h>
00037 #include <dbw_fca_can/pedal_lut.h>
00038
00039 namespace dbw_fca_can
00040 {
00041
00042
00043 PlatformMap FIRMWARE_LATEST({
00044 {PlatformVersion(P_FCA_RU, M_BPEC, ModuleVersion(1,1,0))},
00045 {PlatformVersion(P_FCA_RU, M_TPEC, ModuleVersion(1,1,0))},
00046 {PlatformVersion(P_FCA_RU, M_STEER, ModuleVersion(1,1,0))},
00047 {PlatformVersion(P_FCA_RU, M_SHIFT, ModuleVersion(1,1,0))},
00048 {PlatformVersion(P_FCA_WK2, M_TPEC, ModuleVersion(0,2,0))},
00049 {PlatformVersion(P_FCA_WK2, M_STEER, ModuleVersion(0,2,0))},
00050 {PlatformVersion(P_FCA_WK2, M_SHIFT, ModuleVersion(0,2,0))},
00051 {PlatformVersion(P_FCA_WK2, M_ABS, ModuleVersion(0,2,0))},
00052 });
00053
00054
00055 PlatformMap FIRMWARE_HIGH_RATE_LIMIT({
00056 {PlatformVersion(P_FCA_RU, M_STEER, ModuleVersion(1,1,0))},
00057 {PlatformVersion(P_FCA_WK2, M_STEER, ModuleVersion(0,2,0))},
00058 });
00059
00060 DbwNode::DbwNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh)
00061 {
00062
00063 prev_enable_ = true;
00064 enable_ = false;
00065 override_brake_ = false;
00066 override_throttle_ = false;
00067 override_steering_ = false;
00068 override_gear_ = false;
00069 fault_brakes_ = false;
00070 fault_throttle_ = false;
00071 fault_steering_ = false;
00072 fault_steering_cal_ = false;
00073 fault_watchdog_ = false;
00074 fault_watchdog_using_brakes_ = false;
00075 fault_watchdog_warned_ = false;
00076 timeout_brakes_ = false;
00077 timeout_throttle_ = false;
00078 timeout_steering_ = false;
00079 enabled_brakes_ = false;
00080 enabled_throttle_ = false;
00081 enabled_steering_ = false;
00082 gear_warned_ = false;
00083
00084
00085 frame_id_ = "base_footprint";
00086 priv_nh.getParam("frame_id", frame_id_);
00087
00088
00089 warn_cmds_ = true;
00090 priv_nh.getParam("warn_cmds", warn_cmds_);
00091
00092
00093 buttons_ = true;
00094 priv_nh.getParam("buttons", buttons_);
00095
00096
00097 pedal_luts_ = false;
00098 priv_nh.getParam("pedal_luts", pedal_luts_);
00099
00100
00101 acker_wheelbase_ = 3.08864;
00102 acker_track_ = 1.73228;
00103 steering_ratio_ = 16.2;
00104 wheel_radius_ = 0.365;
00105 priv_nh.getParam("ackermann_wheelbase", acker_wheelbase_);
00106 priv_nh.getParam("ackermann_track", acker_track_);
00107 priv_nh.getParam("steering_ratio", steering_ratio_);
00108
00109
00110 joint_state_.position.resize(JOINT_COUNT);
00111 joint_state_.velocity.resize(JOINT_COUNT);
00112 joint_state_.effort.resize(JOINT_COUNT);
00113 joint_state_.name.resize(JOINT_COUNT);
00114 joint_state_.name[JOINT_FL] = "wheel_fl";
00115 joint_state_.name[JOINT_FR] = "wheel_fr";
00116 joint_state_.name[JOINT_RL] = "wheel_rl";
00117 joint_state_.name[JOINT_RR] = "wheel_rr";
00118 joint_state_.name[JOINT_SL] = "steer_fl";
00119 joint_state_.name[JOINT_SR] = "steer_fr";
00120
00121
00122 pub_can_ = node.advertise<can_msgs::Frame>("can_tx", 10);
00123 pub_brake_ = node.advertise<dbw_fca_msgs::BrakeReport>("brake_report", 2);
00124 pub_throttle_ = node.advertise<dbw_fca_msgs::ThrottleReport>("throttle_report", 2);
00125 pub_steering_ = node.advertise<dbw_fca_msgs::SteeringReport>("steering_report", 2);
00126 pub_gear_ = node.advertise<dbw_fca_msgs::GearReport>("gear_report", 2);
00127 pub_misc_1_ = node.advertise<dbw_fca_msgs::Misc1Report>("misc_1_report", 2);
00128 pub_wheel_speeds_ = node.advertise<dbw_fca_msgs::WheelSpeedReport>("wheel_speed_report", 2);
00129 pub_wheel_positions_ = node.advertise<dbw_fca_msgs::WheelPositionReport>("wheel_position_report", 2);
00130 pub_fuel_level_ = node.advertise<dbw_fca_msgs::FuelLevelReport>("fuel_level_report", 2);
00131 pub_brake_info_ = node.advertise<dbw_fca_msgs::BrakeInfoReport>("brake_info_report", 2);
00132 pub_throttle_info_ = node.advertise<dbw_fca_msgs::ThrottleInfoReport>("throttle_info_report", 2);
00133 pub_joint_states_ = node.advertise<sensor_msgs::JointState>("joint_states", 10);
00134 pub_twist_ = node.advertise<geometry_msgs::TwistStamped>("twist", 10);
00135 pub_vin_ = node.advertise<std_msgs::String>("vin", 1, true);
00136 pub_sys_enable_ = node.advertise<std_msgs::Bool>("dbw_enabled", 1, true);
00137 publishDbwEnabled();
00138
00139
00140 const ros::TransportHints NODELAY = ros::TransportHints().tcpNoDelay();
00141 sub_enable_ = node.subscribe("enable", 10, &DbwNode::recvEnable, this, NODELAY);
00142 sub_disable_ = node.subscribe("disable", 10, &DbwNode::recvDisable, this, NODELAY);
00143 sub_can_ = node.subscribe("can_rx", 100, &DbwNode::recvCAN, this, NODELAY);
00144 sub_brake_ = node.subscribe("brake_cmd", 1, &DbwNode::recvBrakeCmd, this, NODELAY);
00145 sub_throttle_ = node.subscribe("throttle_cmd", 1, &DbwNode::recvThrottleCmd, this, NODELAY);
00146 sub_steering_ = node.subscribe("steering_cmd", 1, &DbwNode::recvSteeringCmd, this, NODELAY);
00147 sub_gear_ = node.subscribe("gear_cmd", 1, &DbwNode::recvGearCmd, this, NODELAY);
00148 sub_turn_signal_ = node.subscribe("turn_signal_cmd", 1, &DbwNode::recvTurnSignalCmd, this, NODELAY);
00149
00150
00151 timer_ = node.createTimer(ros::Duration(1 / 20.0), &DbwNode::timerCallback, this);
00152 }
00153
00154 DbwNode::~DbwNode()
00155 {
00156 }
00157
00158 void DbwNode::recvEnable(const std_msgs::Empty::ConstPtr& msg)
00159 {
00160 enableSystem();
00161 }
00162
00163 void DbwNode::recvDisable(const std_msgs::Empty::ConstPtr& msg)
00164 {
00165 disableSystem();
00166 }
00167
00168 void DbwNode::recvCAN(const can_msgs::Frame::ConstPtr& msg)
00169 {
00170 if (!msg->is_rtr && !msg->is_error && !msg->is_extended) {
00171 switch (msg->id) {
00172 case ID_BRAKE_REPORT:
00173 if (msg->dlc >= sizeof(MsgBrakeReport)) {
00174 const MsgBrakeReport *ptr = (const MsgBrakeReport*)msg->data.elems;
00175 faultBrakes(ptr->FLT1 || ptr->FLT2);
00176 faultWatchdog(ptr->FLTWDC, ptr->WDCSRC, ptr->WDCBRK);
00177 overrideBrake(ptr->OVERRIDE, ptr->TMOUT);
00178 timeoutBrake(ptr->TMOUT, ptr->ENABLED);
00179 dbw_fca_msgs::BrakeReport out;
00180 out.header.stamp = msg->header.stamp;
00182 out.pedal_input = (float)ptr->PI / UINT16_MAX;
00183 out.pedal_cmd = (float)ptr->PC / UINT16_MAX;
00184 out.pedal_output = (float)ptr->PO / UINT16_MAX;
00185 out.torque_input = brakeTorqueFromPedal(out.pedal_input);
00186 out.torque_cmd = brakeTorqueFromPedal(out.pedal_cmd);
00187 out.torque_output = brakeTorqueFromPedal(out.pedal_output);
00188 out.enabled = ptr->ENABLED ? true : false;
00189 out.override = ptr->OVERRIDE ? true : false;
00190 out.driver = ptr->DRIVER ? true : false;
00191 out.watchdog_counter.source = ptr->WDCSRC;
00192 out.watchdog_braking = ptr->WDCBRK ? true : false;
00193 out.fault_wdc = ptr->FLTWDC ? true : false;
00194 out.fault_ch1 = ptr->FLT1 ? true : false;
00195 out.fault_ch2 = ptr->FLT2 ? true : false;
00196 out.fault_power = ptr->FLTPWR ? true : false;
00197 out.timeout = ptr->TMOUT ? true : false;
00198 pub_brake_.publish(out);
00199 if (ptr->FLT1 || ptr->FLT2 || ptr->FLTPWR) {
00200 ROS_WARN_THROTTLE(5.0, "Brake fault. FLT1: %s FLT2: %s FLTPWR: %s",
00201 ptr->FLT1 ? "true, " : "false,",
00202 ptr->FLT2 ? "true, " : "false,",
00203 ptr->FLTPWR ? "true" : "false");
00204 }
00205 }
00206 break;
00207
00208 case ID_THROTTLE_REPORT:
00209 if (msg->dlc >= sizeof(MsgThrottleReport)) {
00210 const MsgThrottleReport *ptr = (const MsgThrottleReport*)msg->data.elems;
00211 faultThrottle(ptr->FLT1 || ptr->FLT2);
00212 faultWatchdog(ptr->FLTWDC, ptr->WDCSRC);
00213 overrideThrottle(ptr->OVERRIDE, ptr->TMOUT);
00214 timeoutThrottle(ptr->TMOUT, ptr->ENABLED);
00215 dbw_fca_msgs::ThrottleReport out;
00216 out.header.stamp = msg->header.stamp;
00217 out.pedal_input = (float)ptr->PI / UINT16_MAX;
00218 out.pedal_cmd = (float)ptr->PC / UINT16_MAX;
00219 out.pedal_output = (float)ptr->PO / UINT16_MAX;
00220 out.enabled = ptr->ENABLED ? true : false;
00221 out.override = ptr->OVERRIDE ? true : false;
00222 out.driver = ptr->DRIVER ? true : false;
00223 out.watchdog_counter.source = ptr->WDCSRC;
00224 out.fault_wdc = ptr->FLTWDC ? true : false;
00225 out.fault_ch1 = ptr->FLT1 ? true : false;
00226 out.fault_ch2 = ptr->FLT2 ? true : false;
00227 out.fault_power = ptr->FLTPWR ? true : false;
00228 out.timeout = ptr->TMOUT ? true : false;
00229 pub_throttle_.publish(out);
00230 if (ptr->FLT1 || ptr->FLT2 || ptr->FLTPWR) {
00231 ROS_WARN_THROTTLE(5.0, "Throttle fault. FLT1: %s FLT2: %s FLTPWR: %s",
00232 ptr->FLT1 ? "true, " : "false,",
00233 ptr->FLT2 ? "true, " : "false,",
00234 ptr->FLTPWR ? "true" : "false");
00235 }
00236 }
00237 break;
00238
00239 case ID_STEERING_REPORT:
00240 if (msg->dlc >= sizeof(MsgSteeringReport)) {
00241 const MsgSteeringReport *ptr = (const MsgSteeringReport*)msg->data.elems;
00242 faultSteering(ptr->FLTBUS1 || ptr->FLTBUS2);
00243 faultSteeringCal(ptr->FLTCAL);
00244 faultWatchdog(ptr->FLTWDC);
00245 overrideSteering(ptr->OVERRIDE, ptr->TMOUT);
00246 timeoutSteering(ptr->TMOUT, ptr->ENABLED);
00247 dbw_fca_msgs::SteeringReport out;
00248 out.header.stamp = msg->header.stamp;
00249 out.steering_wheel_angle = (float)ptr->ANGLE * (float)(0.1 * M_PI / 180);
00250 out.steering_wheel_cmd_type = ptr->TMODE ? dbw_fca_msgs::SteeringReport::CMD_TORQUE : dbw_fca_msgs::SteeringReport::CMD_ANGLE;
00251 if (out.steering_wheel_cmd_type == dbw_fca_msgs::SteeringReport::CMD_ANGLE) {
00252 out.steering_wheel_cmd = (float)ptr->CMD * (float)(0.1 * M_PI / 180);
00253 } else {
00254 out.steering_wheel_cmd = (float)ptr->CMD / 128.0f;
00255 }
00256 out.steering_wheel_torque = (float)ptr->TORQUE * (float)0.0625;
00257 out.speed = (float)ptr->SPEED * (float)(0.01 / 3.6) * (float)speedSign();
00258 out.enabled = ptr->ENABLED ? true : false;
00259 out.override = ptr->OVERRIDE ? true : false;
00260 out.fault_wdc = ptr->FLTWDC ? true : false;
00261 out.fault_bus1 = ptr->FLTBUS1 ? true : false;
00262 out.fault_bus2 = ptr->FLTBUS2 ? true : false;
00263 out.fault_calibration = ptr->FLTCAL ? true : false;
00264 out.fault_power = ptr->FLTPWR ? true : false;
00265 out.timeout = ptr->TMOUT ? true : false;
00266 pub_steering_.publish(out);
00267 geometry_msgs::TwistStamped twist;
00268 twist.header.stamp = out.header.stamp;
00269 twist.header.frame_id = frame_id_;
00270 twist.twist.linear.x = out.speed;
00271 twist.twist.angular.z = out.speed * tan(out.steering_wheel_angle / steering_ratio_) / acker_wheelbase_;
00272 pub_twist_.publish(twist);
00273 publishJointStates(msg->header.stamp, &out);
00274 if (ptr->FLTBUS1 || ptr->FLTBUS2 || ptr->FLTPWR) {
00275 ROS_WARN_THROTTLE(5.0, "Steering fault. FLT1: %s FLT2: %s FLTPWR: %s",
00276 ptr->FLTBUS1 ? "true, " : "false,",
00277 ptr->FLTBUS2 ? "true, " : "false,",
00278 ptr->FLTPWR ? "true" : "false");
00279 } else if (ptr->FLTCAL) {
00280 ROS_WARN_THROTTLE(5.0, "Steering calibration fault. Drive at least 25 mph for at least 10 seconds in a straight line.");
00281 }
00282 }
00283 break;
00284
00285 case ID_GEAR_REPORT:
00286 if (msg->dlc >= 1) {
00287 const MsgGearReport *ptr = (const MsgGearReport*)msg->data.elems;
00288 overrideGear(ptr->OVERRIDE);
00289 dbw_fca_msgs::GearReport out;
00290 out.header.stamp = msg->header.stamp;
00291 out.state.gear = ptr->STATE;
00292 out.cmd.gear = ptr->CMD;
00293 out.override = ptr->OVERRIDE ? true : false;
00294 out.fault_bus = ptr->FLTBUS ? true : false;
00295 if (msg->dlc >= sizeof(MsgGearReport)) {
00296 out.reject.value = ptr->REJECT;
00297 if (out.reject.value == dbw_fca_msgs::GearReject::NONE) {
00298 gear_warned_ = false;
00299 } else if (!gear_warned_) {
00300 gear_warned_ = true;
00301 switch (out.reject.value) {
00302 case dbw_fca_msgs::GearReject::SHIFT_IN_PROGRESS:
00303 ROS_WARN("Gear shift rejected: Shift in progress");
00304 break;
00305 case dbw_fca_msgs::GearReject::OVERRIDE:
00306 ROS_WARN("Gear shift rejected: Override on brake, throttle, or steering");
00307 break;
00308 case dbw_fca_msgs::GearReject::ROTARY_LOW:
00309 ROS_WARN("Gear shift rejected: Rotary shifter can't shift to Low");
00310 break;
00311 case dbw_fca_msgs::GearReject::ROTARY_PARK:
00312 ROS_WARN("Gear shift rejected: Rotary shifter can't shift out of Park");
00313 break;
00314 case dbw_fca_msgs::GearReject::VEHICLE:
00315 ROS_WARN("Gear shift rejected: Rejected by vehicle, try pressing the brakes");
00316 break;
00317 }
00318 }
00319 }
00320 pub_gear_.publish(out);
00321 }
00322 break;
00323
00324 case ID_MISC_REPORT:
00325 if (msg->dlc >= sizeof(MsgMiscReport)) {
00326 const MsgMiscReport *ptr = (const MsgMiscReport*)msg->data.elems;
00327 if (buttons_) {
00328 if (0) {
00329 buttonCancel();
00330 } else if ((ptr->btn_ld_left && ptr->btn_ld_down)) {
00331 enableSystem();
00332 }
00333 }
00334 dbw_fca_msgs::Misc1Report out;
00335 out.header.stamp = msg->header.stamp;
00336 out.turn_signal.value = ptr->turn_signal;
00337 out.btn_cc_on_off = ptr->btn_cc_on_off ? true : false;
00338 out.btn_cc_res = ptr->btn_cc_res ? true : false;
00339 out.btn_cc_cncl = ptr->btn_cc_cncl ? true : false;
00340 out.btn_cc_set_inc = ptr->btn_cc_set_inc ? true : false;
00341 out.btn_cc_set_dec = ptr->btn_cc_set_dec ? true : false;
00342 out.btn_cc_gap_inc = ptr->btn_cc_gap_inc ? true : false;
00343 out.btn_cc_gap_dec = ptr->btn_cc_gap_dec ? true : false;
00344 out.btn_cc_mode = ptr->btn_cc_mode ? true : false;
00345 out.btn_ld_ok = ptr->btn_ld_ok ? true : false;
00346 out.btn_ld_up = ptr->btn_ld_up ? true : false;
00347 out.btn_ld_down = ptr->btn_ld_down ? true : false;
00348 out.btn_ld_left = ptr->btn_ld_left ? true : false;
00349 out.btn_ld_right = ptr->btn_ld_right ? true : false;
00350 out.fault_bus = ptr->FLTBUS ? true : false;
00351 pub_misc_1_.publish(out);
00352 }
00353 break;
00354
00355 case ID_REPORT_WHEEL_SPEED:
00356 if (msg->dlc >= sizeof(MsgReportWheelSpeed)) {
00357 const MsgReportWheelSpeed *ptr = (const MsgReportWheelSpeed*)msg->data.elems;
00358 dbw_fca_msgs::WheelSpeedReport out;
00359 out.header.stamp = msg->header.stamp;
00360 out.front_left = (float)ptr->front_left * 0.01f;
00361 out.front_right = (float)ptr->front_right * 0.01f;
00362 out.rear_left = (float)ptr->rear_left * 0.01f;
00363 out.rear_right = (float)ptr->rear_right * 0.01f;
00364 pub_wheel_speeds_.publish(out);
00365 }
00366 break;
00367
00368 case ID_REPORT_WHEEL_POSITION:
00369 if (msg->dlc >= sizeof(MsgReportWheelPosition)) {
00370 const MsgReportWheelPosition *ptr = (const MsgReportWheelPosition*)msg->data.elems;
00371 dbw_fca_msgs::WheelPositionReport out;
00372 out.header.stamp = msg->header.stamp;
00373 out.front_left = ptr->front_left;
00374 out.front_right = ptr->front_right;
00375 out.rear_left = ptr->rear_left;
00376 out.rear_right = ptr->rear_right;
00377 pub_wheel_positions_.publish(out);
00378 }
00379 break;
00380
00381 case ID_REPORT_FUEL_LEVEL:
00382 if (msg->dlc >= 2) {
00383 const MsgReportFuelLevel *ptr = (const MsgReportFuelLevel*)msg->data.elems;
00384 dbw_fca_msgs::FuelLevelReport out;
00385 out.header.stamp = msg->header.stamp;
00386 out.fuel_level = (float)ptr->fuel_level * 0.108696f;
00387 if (msg->dlc >= sizeof(MsgReportFuelLevel)) {
00388 out.battery_12v = (float)ptr->battery_12v * 0.0625f;
00389 out.odometer = (float)ptr->odometer * 0.1f;
00390 }
00391 pub_fuel_level_.publish(out);
00392 }
00393 break;
00394
00395 case ID_REPORT_BRAKE_INFO:
00396 if (msg->dlc >= sizeof(MsgReportBrakeInfo)) {
00397 const MsgReportBrakeInfo *ptr = (const MsgReportBrakeInfo*)msg->data.elems;
00398 dbw_fca_msgs::BrakeInfoReport out;
00399 out.header.stamp = msg->header.stamp;
00400 out.brake_pc = (float)ptr->brake_pc * 0.4;
00401 out.brake_torque_request = (float)ptr->brake_torque_request * 3.0f;
00402 out.brake_torque_actual = (float)ptr->brake_torque_actual * 3.0f;
00403 out.brake_pressure = (float)ptr->brake_pressure * 0.1f;
00404 out.stationary = ptr->stationary;
00405 pub_brake_info_.publish(out);
00406 }
00407 break;
00408
00409 case ID_REPORT_THROTTLE_INFO:
00410 if (msg->dlc >= sizeof(MsgReportThrottleInfo)) {
00411 const MsgReportThrottleInfo *ptr = (const MsgReportThrottleInfo*)msg->data.elems;
00412 dbw_fca_msgs::ThrottleInfoReport out;
00413 out.header.stamp = msg->header.stamp;
00414 out.throttle_pc = (float)ptr->throttle_pc * 0.4f;
00415 out.axle_torque = (float)ptr->axle_torque * 1.5625f;
00416 pub_throttle_info_.publish(out);
00417 }
00418 break;
00419
00420 case ID_LICENSE:
00421 if (msg->dlc >= sizeof(MsgLicense)) {
00422 const MsgLicense *ptr = (const MsgLicense*)msg->data.elems;
00423 if (ptr->ready) {
00424 ROS_INFO_ONCE("DBW Licensing: Ready");
00425 if (ptr->trial) {
00426 ROS_WARN_ONCE("DBW Licensing: One or more features licensed as a counted trial. Visit http://dataspeedinc.com/maintenance/ to request a full license.");
00427 }
00428 if (ptr->expired) {
00429 ROS_WARN_ONCE("DBW Licensing: One or more feature licenses expired due to the firmware build date");
00430 }
00431 } else {
00432 ROS_INFO_THROTTLE(10.0, "DBW Licensing: Waiting to resolve VIN...");
00433 }
00434 if (ptr->mux == LIC_MUX_MAC) {
00435 ROS_INFO_ONCE("Detected firmware MAC: %02X:%02X:%02X:%02X:%02X:%02X",
00436 ptr->mac.addr0, ptr->mac.addr1,
00437 ptr->mac.addr2, ptr->mac.addr3,
00438 ptr->mac.addr4, ptr->mac.addr5);
00439 } else if (ptr->mux == LIC_MUX_DATE0) {
00440 if (date_.size() == 0) {
00441 date_.push_back(ptr->date0.date0);
00442 date_.push_back(ptr->date0.date1);
00443 date_.push_back(ptr->date0.date2);
00444 date_.push_back(ptr->date0.date3);
00445 date_.push_back(ptr->date0.date4);
00446 date_.push_back(ptr->date0.date5);
00447 }
00448 } else if (ptr->mux == LIC_MUX_DATE1) {
00449 if (date_.size() == 6) {
00450 date_.push_back(ptr->date1.date6);
00451 date_.push_back(ptr->date1.date7);
00452 date_.push_back(ptr->date1.date8);
00453 date_.push_back(ptr->date1.date9);
00454 ROS_INFO("Detected firmware build date: %s", date_.c_str());
00455 }
00456 } else if (ptr->mux == LIC_MUX_VIN0) {
00457 if (vin_.size() == 0) {
00458 vin_.push_back(ptr->vin0.vin00);
00459 vin_.push_back(ptr->vin0.vin01);
00460 vin_.push_back(ptr->vin0.vin02);
00461 vin_.push_back(ptr->vin0.vin03);
00462 vin_.push_back(ptr->vin0.vin04);
00463 vin_.push_back(ptr->vin0.vin05);
00464 }
00465 } else if (ptr->mux == LIC_MUX_VIN1) {
00466 if (vin_.size() == 6) {
00467 vin_.push_back(ptr->vin1.vin06);
00468 vin_.push_back(ptr->vin1.vin07);
00469 vin_.push_back(ptr->vin1.vin08);
00470 vin_.push_back(ptr->vin1.vin09);
00471 vin_.push_back(ptr->vin1.vin10);
00472 vin_.push_back(ptr->vin1.vin11);
00473 }
00474 } else if (ptr->mux == LIC_MUX_VIN2) {
00475 if (vin_.size() == 12) {
00476 vin_.push_back(ptr->vin2.vin12);
00477 vin_.push_back(ptr->vin2.vin13);
00478 vin_.push_back(ptr->vin2.vin14);
00479 vin_.push_back(ptr->vin2.vin15);
00480 vin_.push_back(ptr->vin2.vin16);
00481 std_msgs::String msg; msg.data = vin_;
00482 pub_vin_.publish(msg);
00483 ROS_INFO("Detected VIN: %s", vin_.c_str());
00484 }
00485 } else if (ptr->mux == LIC_MUX_F0) {
00486 const char * const NAME = "BASE";
00487 if (ptr->license.enabled) {
00488 ROS_INFO_ONCE("DBW Licensing: Feature '%s' enabled%s", NAME, ptr->license.trial ? " as a counted trial" : "");
00489 } else if (ptr->ready) {
00490 ROS_WARN_ONCE("DBW Licensing: Feature '%s' not licensed. Visit http://dataspeedinc.com/maintenance/ to request a license.", NAME);
00491 }
00492 if (ptr->ready && (ptr->license.trial || !ptr->license.enabled)) {
00493 ROS_INFO_ONCE("DBW Licensing: Feature '%s' trials used: %u, remaining: %u", NAME,
00494 ptr->license.trials_used, ptr->license.trials_left);
00495 }
00496 }
00497 }
00498 break;
00499
00500 case ID_VERSION:
00501 if (msg->dlc >= sizeof(MsgVersion)) {
00502 const MsgVersion *ptr = (const MsgVersion*)msg->data.elems;
00503 const PlatformVersion version((Platform)ptr->platform, (Module)ptr->module, ptr->major, ptr->minor, ptr->build);
00504 const ModuleVersion latest = FIRMWARE_LATEST.findModule(version);
00505 const char * str_p = platformToString(version.p);
00506 const char * str_m = moduleToString(version.m);
00507 if (firmware_.findModule(version) != version.v) {
00508 firmware_.insert(version);
00509 if (latest.valid()) {
00510 ROS_INFO("Detected %s %s firmware version %u.%u.%u", str_p, str_m, ptr->major, ptr->minor, ptr->build);
00511 } else {
00512 ROS_WARN("Detected %s %s firmware version %u.%u.%u, which is unsupported. Platform: 0x%02X, Module: %u", str_p, str_m,
00513 ptr->major, ptr->minor, ptr->build, ptr->platform, ptr->module);
00514 }
00515 if (version < latest) {
00516 ROS_WARN("Firmware %s %s has old version %u.%u.%u, updating to %u.%u.%u is suggested.", str_p, str_m,
00517 version.v.major(), version.v.minor(), version.v.build(),
00518 latest.major(), latest.minor(), latest.build());
00519 }
00520 }
00521 }
00522 break;
00523
00524 case ID_BRAKE_CMD:
00525 ROS_WARN_COND(warn_cmds_ && !((const MsgBrakeCmd*)msg->data.elems)->RES1,
00526 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Brake. Id: 0x%03X", ID_BRAKE_CMD);
00527 break;
00528 case ID_THROTTLE_CMD:
00529 ROS_WARN_COND(warn_cmds_ && !((const MsgThrottleCmd*)msg->data.elems)->RES1,
00530 "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Throttle. Id: 0x%03X", ID_THROTTLE_CMD);
00531 break;
00532 case ID_STEERING_CMD:
00533 ROS_WARN_COND(warn_cmds_, "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Steering. Id: 0x%03X", ID_STEERING_CMD);
00534 break;
00535 case ID_GEAR_CMD:
00536 ROS_WARN_COND(warn_cmds_, "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Shifting. Id: 0x%03X", ID_GEAR_CMD);
00537 break;
00538 case ID_MISC_CMD:
00539 ROS_WARN_COND(warn_cmds_, "DBW system: Another node on the CAN bus is commanding the vehicle!!! Subsystem: Turn Signals. Id: 0x%03X", ID_MISC_CMD);
00540 break;
00541 }
00542 }
00543 #if 0
00544 ROS_INFO("ena: %s, clr: %s, brake: %s, throttle: %s, steering: %s, gear: %s",
00545 enabled() ? "true " : "false",
00546 clear() ? "true " : "false",
00547 override_brake_ ? "true " : "false",
00548 override_throttle_ ? "true " : "false",
00549 override_steering_ ? "true " : "false",
00550 override_gear_ ? "true " : "false"
00551 );
00552 #endif
00553 }
00554
00555 void DbwNode::recvBrakeCmd(const dbw_fca_msgs::BrakeCmd::ConstPtr& msg)
00556 {
00557 can_msgs::Frame out;
00558 out.id = ID_BRAKE_CMD;
00559 out.is_extended = false;
00560 out.dlc = sizeof(MsgBrakeCmd);
00561 MsgBrakeCmd *ptr = (MsgBrakeCmd*)out.data.elems;
00562 memset(ptr, 0x00, sizeof(*ptr));
00563 if (enabled()) {
00564 bool fwd_abs = firmware_.findModule(M_ABS).valid();
00565 bool fwd = !pedal_luts_;
00566 fwd |= fwd_abs;
00567 switch (msg->pedal_cmd_type) {
00568 case dbw_fca_msgs::BrakeCmd::CMD_NONE:
00569 break;
00570 case dbw_fca_msgs::BrakeCmd::CMD_PEDAL:
00571 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_PEDAL;
00572 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, msg->pedal_cmd * UINT16_MAX));
00573 if (!firmware_.findModule(M_BPEC).valid() && firmware_.findModule(M_ABS).valid()) {
00574 ROS_WARN_THROTTLE(1.0, "Module ABS does not support brake command type PEDAL");
00575 }
00576 break;
00577 case dbw_fca_msgs::BrakeCmd::CMD_PERCENT:
00578 if (fwd) {
00579 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_PERCENT;
00580 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, msg->pedal_cmd * UINT16_MAX));
00581 } else {
00582 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_PEDAL;
00583 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, brakePedalFromPercent(msg->pedal_cmd) * UINT16_MAX));
00584 }
00585 break;
00586 case dbw_fca_msgs::BrakeCmd::CMD_TORQUE:
00587 if (fwd) {
00588 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_TORQUE;
00589 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, msg->pedal_cmd));
00590 } else {
00591 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_PEDAL;
00592 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, brakePedalFromTorque(msg->pedal_cmd) * UINT16_MAX));
00593 }
00594 if (!firmware_.findModule(M_BPEC).valid() && firmware_.findModule(M_ABS).valid()) {
00595 ROS_WARN_THROTTLE(1.0, "Module ABS does not support brake command type TORQUE");
00596 }
00597 break;
00598 case dbw_fca_msgs::BrakeCmd::CMD_TORQUE_RQ:
00599
00600 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_TORQUE_RQ;
00601 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, msg->pedal_cmd));
00602 if (!firmware_.findModule(M_BPEC).valid() && firmware_.findModule(M_ABS).valid()) {
00603 ROS_WARN_THROTTLE(1.0, "Module ABS does not support brake command type TORQUE_RQ");
00604 }
00605 break;
00606 case dbw_fca_msgs::BrakeCmd::CMD_DECEL:
00607
00608 ptr->CMD_TYPE = dbw_fca_msgs::BrakeCmd::CMD_DECEL;
00609 ptr->PCMD = std::max((float)0.0, std::min((float)10e3, msg->pedal_cmd * 1e3f));
00610 if (!firmware_.findModule(M_ABS).valid() && firmware_.findModule(M_BPEC).valid()) {
00611 ROS_WARN_THROTTLE(1.0, "Module BPEC does not support brake command type DECEL");
00612 }
00613 break;
00614 default:
00615 ROS_WARN("Unknown brake command type: %u", msg->pedal_cmd_type);
00616 break;
00617 }
00618 if (msg->enable) {
00619 ptr->EN = 1;
00620 }
00621 }
00622 if (clear() || msg->clear) {
00623 ptr->CLEAR = 1;
00624 }
00625 if (msg->ignore) {
00626 ptr->IGNORE = 1;
00627 }
00628 ptr->COUNT = msg->count;
00629 pub_can_.publish(out);
00630 }
00631
00632 void DbwNode::recvThrottleCmd(const dbw_fca_msgs::ThrottleCmd::ConstPtr& msg)
00633 {
00634 can_msgs::Frame out;
00635 out.id = ID_THROTTLE_CMD;
00636 out.is_extended = false;
00637 out.dlc = sizeof(MsgThrottleCmd);
00638 MsgThrottleCmd *ptr = (MsgThrottleCmd*)out.data.elems;
00639 memset(ptr, 0x00, sizeof(*ptr));
00640 if (enabled()) {
00641 bool fwd = !pedal_luts_;
00642 float cmd = 0.0;
00643 switch (msg->pedal_cmd_type) {
00644 case dbw_fca_msgs::ThrottleCmd::CMD_NONE:
00645 break;
00646 case dbw_fca_msgs::ThrottleCmd::CMD_PEDAL:
00647 ptr->CMD_TYPE = dbw_fca_msgs::ThrottleCmd::CMD_PEDAL;
00648 cmd = msg->pedal_cmd;
00649 break;
00650 case dbw_fca_msgs::ThrottleCmd::CMD_PERCENT:
00651 if (fwd) {
00652 ptr->CMD_TYPE = dbw_fca_msgs::ThrottleCmd::CMD_PERCENT;
00653 cmd = msg->pedal_cmd;
00654 } else {
00655 ptr->CMD_TYPE = dbw_fca_msgs::ThrottleCmd::CMD_PEDAL;
00656 cmd = throttlePedalFromPercent(msg->pedal_cmd);
00657 }
00658 break;
00659 default:
00660 ROS_WARN("Unknown throttle command type: %u", msg->pedal_cmd_type);
00661 break;
00662 }
00663 ptr->PCMD = std::max((float)0.0, std::min((float)UINT16_MAX, cmd * UINT16_MAX));
00664 if (msg->enable) {
00665 ptr->EN = 1;
00666 }
00667 }
00668 if (clear() || msg->clear) {
00669 ptr->CLEAR = 1;
00670 }
00671 if (msg->ignore) {
00672 ptr->IGNORE = 1;
00673 }
00674 ptr->COUNT = msg->count;
00675 pub_can_.publish(out);
00676 }
00677
00678 void DbwNode::recvSteeringCmd(const dbw_fca_msgs::SteeringCmd::ConstPtr& msg)
00679 {
00680 can_msgs::Frame out;
00681 out.id = ID_STEERING_CMD;
00682 out.is_extended = false;
00683 out.dlc = sizeof(MsgSteeringCmd);
00684 MsgSteeringCmd *ptr = (MsgSteeringCmd*)out.data.elems;
00685 memset(ptr, 0x00, sizeof(*ptr));
00686 if (enabled()) {
00687 switch (msg->cmd_type) {
00688 case dbw_fca_msgs::SteeringCmd::CMD_ANGLE:
00689 ptr->SCMD = std::max((float)-INT16_MAX, std::min((float)INT16_MAX, (float)(msg->steering_wheel_angle_cmd * (180 / M_PI * 10))));
00690 if (fabsf(msg->steering_wheel_angle_velocity) > 0) {
00691 if (firmware_.findPlatform(M_STEER) >= FIRMWARE_HIGH_RATE_LIMIT) {
00692 ptr->SVEL = std::max((float)1, std::min((float)254, (float)roundf(fabsf(msg->steering_wheel_angle_velocity) * 180 / M_PI / 4)));
00693 } else {
00694 ptr->SVEL = std::max((float)1, std::min((float)254, (float)roundf(fabsf(msg->steering_wheel_angle_velocity) * 180 / M_PI / 2)));
00695 }
00696 }
00697 ptr->CMD_TYPE = dbw_fca_msgs::SteeringCmd::CMD_ANGLE;
00698 break;
00699 case dbw_fca_msgs::SteeringCmd::CMD_TORQUE:
00700 ptr->SCMD = std::max((float)-INT16_MAX, std::min((float)INT16_MAX, (float)(msg->steering_wheel_torque_cmd * 128)));
00701 ptr->CMD_TYPE = dbw_fca_msgs::SteeringCmd::CMD_TORQUE;
00702 break;
00703 default:
00704 ROS_WARN("Unknown steering command type: %u", msg->cmd_type);
00705 break;
00706 }
00707 if (msg->enable) {
00708 ptr->EN = 1;
00709 }
00710 }
00711 if (clear() || msg->clear) {
00712 ptr->CLEAR = 1;
00713 }
00714 if (msg->ignore) {
00715 ptr->IGNORE = 1;
00716 }
00717 if (msg->quiet) {
00718 ptr->QUIET = 1;
00719 }
00720 ptr->COUNT = msg->count;
00721 pub_can_.publish(out);
00722 }
00723
00724 void DbwNode::recvGearCmd(const dbw_fca_msgs::GearCmd::ConstPtr& msg)
00725 {
00726 can_msgs::Frame out;
00727 out.id = ID_GEAR_CMD;
00728 out.is_extended = false;
00729 out.dlc = sizeof(MsgGearCmd);
00730 MsgGearCmd *ptr = (MsgGearCmd*)out.data.elems;
00731 memset(ptr, 0x00, sizeof(*ptr));
00732 if (enabled()) {
00733 ptr->GCMD = msg->cmd.gear;
00734 }
00735 if (clear() || msg->clear) {
00736 ptr->CLEAR = 1;
00737 }
00738 pub_can_.publish(out);
00739 }
00740
00741 void DbwNode::recvTurnSignalCmd(const dbw_fca_msgs::TurnSignalCmd::ConstPtr& msg)
00742 {
00743 can_msgs::Frame out;
00744 out.id = ID_MISC_CMD;
00745 out.is_extended = false;
00746 out.dlc = sizeof(MsgTurnSignalCmd);
00747 MsgTurnSignalCmd *ptr = (MsgTurnSignalCmd*)out.data.elems;
00748 memset(ptr, 0x00, sizeof(*ptr));
00749 if (enabled()) {
00750 ptr->TRNCMD = msg->cmd.value;
00751 }
00752 pub_can_.publish(out);
00753 }
00754
00755 bool DbwNode::publishDbwEnabled()
00756 {
00757 bool change = false;
00758 bool en = enabled();
00759 if (prev_enable_ != en) {
00760 std_msgs::Bool msg;
00761 msg.data = en;
00762 pub_sys_enable_.publish(msg);
00763 change = true;
00764 }
00765 prev_enable_ = en;
00766 return change;
00767 }
00768
00769 void DbwNode::timerCallback(const ros::TimerEvent& event)
00770 {
00771 if (clear()) {
00772 can_msgs::Frame out;
00773 out.is_extended = false;
00774
00775 if (override_brake_) {
00776 out.id = ID_BRAKE_CMD;
00777 out.dlc = 4;
00778 memset(out.data.elems, 0x00, 8);
00779 ((MsgBrakeCmd*)out.data.elems)->CLEAR = 1;
00780 pub_can_.publish(out);
00781 }
00782
00783 if (override_throttle_) {
00784 out.id = ID_THROTTLE_CMD;
00785 out.dlc = 4;
00786 memset(out.data.elems, 0x00, 8);
00787 ((MsgThrottleCmd*)out.data.elems)->CLEAR = 1;
00788 pub_can_.publish(out);
00789 }
00790
00791 if (override_steering_) {
00792 out.id = ID_STEERING_CMD;
00793 out.dlc = 4;
00794 memset(out.data.elems, 0x00, 8);
00795 ((MsgSteeringCmd*)out.data.elems)->CLEAR = 1;
00796 pub_can_.publish(out);
00797 }
00798
00799 if (override_gear_) {
00800 out.id = ID_GEAR_CMD;
00801 out.dlc = sizeof(MsgGearCmd);
00802 memset(out.data.elems, 0x00, 8);
00803 ((MsgGearCmd*)out.data.elems)->CLEAR = 1;
00804 pub_can_.publish(out);
00805 }
00806 }
00807 }
00808
00809 void DbwNode::enableSystem()
00810 {
00811 if (!enable_) {
00812 if (fault()) {
00813 if (fault_steering_cal_) {
00814 ROS_WARN("DBW system not enabled. Steering calibration fault.");
00815 }
00816 if (fault_brakes_) {
00817 ROS_WARN("DBW system not enabled. Braking fault.");
00818 }
00819 if (fault_throttle_) {
00820 ROS_WARN("DBW system not enabled. Throttle fault.");
00821 }
00822 if (fault_steering_) {
00823 ROS_WARN("DBW system not enabled. Steering fault.");
00824 }
00825 if (fault_watchdog_) {
00826 ROS_WARN("DBW system not enabled. Watchdog fault.");
00827 }
00828 } else {
00829 enable_ = true;
00830 if (publishDbwEnabled()) {
00831 ROS_INFO("DBW system enabled.");
00832 } else {
00833 ROS_INFO("DBW system enable requested. Waiting for ready.");
00834 }
00835 }
00836 }
00837 }
00838
00839 void DbwNode::disableSystem()
00840 {
00841 if (enable_) {
00842 enable_ = false;
00843 publishDbwEnabled();
00844 ROS_WARN("DBW system disabled.");
00845 }
00846 }
00847
00848 void DbwNode::buttonCancel()
00849 {
00850 if (enable_) {
00851 enable_ = false;
00852 publishDbwEnabled();
00853 ROS_WARN("DBW system disabled. Cancel button pressed.");
00854 }
00855 }
00856
00857 void DbwNode::overrideBrake(bool override, bool timeout)
00858 {
00859 bool en = enabled();
00860 if (en && timeout) {
00861 override = false;
00862 }
00863 if (en && override) {
00864 enable_ = false;
00865 }
00866 override_brake_ = override;
00867 if (publishDbwEnabled()) {
00868 if (en) {
00869 ROS_WARN("DBW system disabled. Driver override on brake/throttle pedal.");
00870 } else {
00871 ROS_INFO("DBW system enabled.");
00872 }
00873 }
00874 }
00875
00876 void DbwNode::overrideThrottle(bool override, bool timeout)
00877 {
00878 bool en = enabled();
00879 if (en && timeout) {
00880 override = false;
00881 }
00882 if (en && override) {
00883 enable_ = false;
00884 }
00885 override_throttle_ = override;
00886 if (publishDbwEnabled()) {
00887 if (en) {
00888 ROS_WARN("DBW system disabled. Driver override on brake/throttle pedal.");
00889 } else {
00890 ROS_INFO("DBW system enabled.");
00891 }
00892 }
00893 }
00894
00895 void DbwNode::overrideSteering(bool override, bool timeout)
00896 {
00897 bool en = enabled();
00898 if (en && timeout) {
00899 override = false;
00900 }
00901 if (en && override) {
00902 enable_ = false;
00903 }
00904 override_steering_ = override;
00905 if (publishDbwEnabled()) {
00906 if (en) {
00907 ROS_WARN("DBW system disabled. Driver override on steering wheel.");
00908 } else {
00909 ROS_INFO("DBW system enabled.");
00910 }
00911 }
00912 }
00913
00914 void DbwNode::overrideGear(bool override)
00915 {
00916 bool en = enabled();
00917 if (en && override) {
00918 enable_ = false;
00919 }
00920 override_gear_ = override;
00921 if (publishDbwEnabled()) {
00922 if (en) {
00923 ROS_WARN("DBW system disabled. Driver override on shifter.");
00924 } else {
00925 ROS_INFO("DBW system enabled.");
00926 }
00927 }
00928 }
00929
00930 void DbwNode::timeoutBrake(bool timeout, bool enabled)
00931 {
00932 if (!timeout_brakes_ && enabled_brakes_ && timeout && !enabled) {
00933 ROS_WARN("Brake subsystem disabled after 100ms command timeout");
00934 }
00935 timeout_brakes_ = timeout;
00936 enabled_brakes_ = enabled;
00937 }
00938
00939 void DbwNode::timeoutThrottle(bool timeout, bool enabled)
00940 {
00941 if (!timeout_throttle_ && enabled_throttle_ && timeout && !enabled) {
00942 ROS_WARN("Throttle subsystem disabled after 100ms command timeout");
00943 }
00944 timeout_throttle_ = timeout;
00945 enabled_throttle_ = enabled;
00946 }
00947
00948 void DbwNode::timeoutSteering(bool timeout, bool enabled)
00949 {
00950 if (!timeout_steering_ && enabled_steering_ && timeout && !enabled) {
00951 ROS_WARN("Steering subsystem disabled after 100ms command timeout");
00952 }
00953 timeout_steering_ = timeout;
00954 enabled_steering_ = enabled;
00955 }
00956
00957 void DbwNode::faultBrakes(bool fault)
00958 {
00959 bool en = enabled();
00960 if (fault && en) {
00961 enable_ = false;
00962 }
00963 fault_brakes_ = fault;
00964 if (publishDbwEnabled()) {
00965 if (en) {
00966 ROS_ERROR("DBW system disabled. Braking fault.");
00967 } else {
00968 ROS_INFO("DBW system enabled.");
00969 }
00970 }
00971 }
00972
00973 void DbwNode::faultThrottle(bool fault)
00974 {
00975 bool en = enabled();
00976 if (fault && en) {
00977 enable_ = false;
00978 }
00979 fault_throttle_ = fault;
00980 if (publishDbwEnabled()) {
00981 if (en) {
00982 ROS_ERROR("DBW system disabled. Throttle fault.");
00983 } else {
00984 ROS_INFO("DBW system enabled.");
00985 }
00986 }
00987 }
00988
00989 void DbwNode::faultSteering(bool fault)
00990 {
00991 bool en = enabled();
00992 if (fault && en) {
00993 enable_ = false;
00994 }
00995 fault_steering_ = fault;
00996 if (publishDbwEnabled()) {
00997 if (en) {
00998 ROS_ERROR("DBW system disabled. Steering fault.");
00999 } else {
01000 ROS_INFO("DBW system enabled.");
01001 }
01002 }
01003 }
01004
01005 void DbwNode::faultSteeringCal(bool fault)
01006 {
01007 bool en = enabled();
01008 if (fault && en) {
01009 enable_ = false;
01010 }
01011 fault_steering_cal_ = fault;
01012 if (publishDbwEnabled()) {
01013 if (en) {
01014 ROS_ERROR("DBW system disabled. Steering calibration fault.");
01015 } else {
01016 ROS_INFO("DBW system enabled.");
01017 }
01018 }
01019 }
01020
01021 void DbwNode::faultWatchdog(bool fault, uint8_t src, bool braking)
01022 {
01023 bool en = enabled();
01024 if (fault && en) {
01025 enable_ = false;
01026 }
01027 fault_watchdog_ = fault;
01028 if (publishDbwEnabled()) {
01029 if (en) {
01030 ROS_ERROR("DBW system disabled. Watchdog fault.");
01031 } else {
01032 ROS_INFO("DBW system enabled.");
01033 }
01034 }
01035 if (braking && !fault_watchdog_using_brakes_) {
01036 ROS_WARN("Watchdog event: Alerting driver and applying brakes.");
01037 } else if (!braking && fault_watchdog_using_brakes_) {
01038 ROS_INFO("Watchdog event: Driver has successfully taken control.");
01039 }
01040 if (fault && src && !fault_watchdog_warned_) {
01041 switch (src) {
01042 case dbw_fca_msgs::WatchdogCounter::OTHER_BRAKE:
01043 ROS_WARN("Watchdog event: Fault determined by brake controller");
01044 break;
01045 case dbw_fca_msgs::WatchdogCounter::OTHER_THROTTLE:
01046 ROS_WARN("Watchdog event: Fault determined by throttle controller");
01047 break;
01048 case dbw_fca_msgs::WatchdogCounter::OTHER_STEERING:
01049 ROS_WARN("Watchdog event: Fault determined by steering controller");
01050 break;
01051 case dbw_fca_msgs::WatchdogCounter::BRAKE_COUNTER:
01052 ROS_WARN("Watchdog event: Brake command counter failed to increment");
01053 break;
01054 case dbw_fca_msgs::WatchdogCounter::BRAKE_DISABLED:
01055 ROS_WARN("Watchdog event: Brake transition to disabled while in gear or moving");
01056 break;
01057 case dbw_fca_msgs::WatchdogCounter::BRAKE_COMMAND:
01058 ROS_WARN("Watchdog event: Brake command timeout after 100ms");
01059 break;
01060 case dbw_fca_msgs::WatchdogCounter::BRAKE_REPORT:
01061 ROS_WARN("Watchdog event: Brake report timeout after 100ms");
01062 break;
01063 case dbw_fca_msgs::WatchdogCounter::THROTTLE_COUNTER:
01064 ROS_WARN("Watchdog event: Throttle command counter failed to increment");
01065 break;
01066 case dbw_fca_msgs::WatchdogCounter::THROTTLE_DISABLED:
01067 ROS_WARN("Watchdog event: Throttle transition to disabled while in gear or moving");
01068 break;
01069 case dbw_fca_msgs::WatchdogCounter::THROTTLE_COMMAND:
01070 ROS_WARN("Watchdog event: Throttle command timeout after 100ms");
01071 break;
01072 case dbw_fca_msgs::WatchdogCounter::THROTTLE_REPORT:
01073 ROS_WARN("Watchdog event: Throttle report timeout after 100ms");
01074 break;
01075 case dbw_fca_msgs::WatchdogCounter::STEERING_COUNTER:
01076 ROS_WARN("Watchdog event: Steering command counter failed to increment");
01077 break;
01078 case dbw_fca_msgs::WatchdogCounter::STEERING_DISABLED:
01079 ROS_WARN("Watchdog event: Steering transition to disabled while in gear or moving");
01080 break;
01081 case dbw_fca_msgs::WatchdogCounter::STEERING_COMMAND:
01082 ROS_WARN("Watchdog event: Steering command timeout after 100ms");
01083 break;
01084 case dbw_fca_msgs::WatchdogCounter::STEERING_REPORT:
01085 ROS_WARN("Watchdog event: Steering report timeout after 100ms");
01086 break;
01087 }
01088 fault_watchdog_warned_ = true;
01089 } else if (!fault) {
01090 fault_watchdog_warned_ = false;
01091 }
01092 fault_watchdog_using_brakes_ = braking;
01093 if (fault && !fault_watchdog_using_brakes_ && fault_watchdog_warned_) {
01094 ROS_WARN_THROTTLE(2.0, "Watchdog event: Press left OK button on the steering wheel or cycle power to clear event.");
01095 }
01096 }
01097
01098 void DbwNode::faultWatchdog(bool fault, uint8_t src) {
01099 faultWatchdog(fault, src, fault_watchdog_using_brakes_);
01100 }
01101
01102 void DbwNode::publishJointStates(const ros::Time &stamp, const dbw_fca_msgs::SteeringReport *steering)
01103 {
01104 double dt = (stamp - joint_state_.header.stamp).toSec();
01105 if (steering) {
01106 const double L = acker_wheelbase_;
01107 const double W = acker_track_;
01108 const double r = L / tan(steering->steering_wheel_angle / steering_ratio_);
01109 joint_state_.position[JOINT_SL] = atan(L / (r - W/2));
01110 joint_state_.position[JOINT_SR] = atan(L / (r + W/2));
01111 joint_state_.velocity[JOINT_FL] = steering->speed / wheel_radius_;
01112 joint_state_.velocity[JOINT_FR] = steering->speed / wheel_radius_;
01113 joint_state_.velocity[JOINT_RL] = steering->speed / wheel_radius_;
01114 joint_state_.velocity[JOINT_RR] = steering->speed / wheel_radius_;
01115 }
01116 if (dt < 0.5) {
01117 for (unsigned int i = JOINT_FL; i <= JOINT_RR; i++) {
01118 joint_state_.position[i] = fmod(joint_state_.position[i] + dt * joint_state_.velocity[i], 2*M_PI);
01119 }
01120 }
01121 joint_state_.header.stamp = stamp;
01122 pub_joint_states_.publish(joint_state_);
01123 }
01124
01125 }
01126