pacmod3_core.cpp
Go to the documentation of this file.
00001 /*
00002 * Unpublished Copyright (c) 2009-2017 AutonomouStuff, LLC, All Rights Reserved.
00003 *
00004 * This file is part of the PACMod v3 ROS 1.0 driver which is released under the MIT license.
00005 * See file LICENSE included with this software or go to https://opensource.org/licenses/MIT for full license details.
00006 */
00007 
00008 #include <pacmod3_core.h>
00009 
00010 using namespace AS::Drivers::PACMod3;
00011 
00012 const int64_t AS::Drivers::PACMod3::GlobalRptMsg::CAN_ID = 0x10;
00013 
00014 // System Commands
00015 const int64_t AS::Drivers::PACMod3::AccelCmdMsg::CAN_ID = 0x100;
00016 const int64_t AS::Drivers::PACMod3::BrakeCmdMsg::CAN_ID = 0x104;
00017 const int64_t AS::Drivers::PACMod3::CruiseControlButtonsCmdMsg::CAN_ID = 0x108;
00018 const int64_t AS::Drivers::PACMod3::DashControlsLeftCmdMsg::CAN_ID = 0x10C;
00019 const int64_t AS::Drivers::PACMod3::DashControlsRightCmdMsg::CAN_ID = 0x110;
00020 const int64_t AS::Drivers::PACMod3::HazardLightCmdMsg::CAN_ID = 0x114;
00021 const int64_t AS::Drivers::PACMod3::HeadlightCmdMsg::CAN_ID = 0x118;
00022 const int64_t AS::Drivers::PACMod3::HornCmdMsg::CAN_ID = 0x11C;
00023 const int64_t AS::Drivers::PACMod3::MediaControlsCmdMsg::CAN_ID = 0x120;
00024 const int64_t AS::Drivers::PACMod3::ParkingBrakeCmdMsg::CAN_ID = 0x124;
00025 const int64_t AS::Drivers::PACMod3::ShiftCmdMsg::CAN_ID = 0x128;
00026 const int64_t AS::Drivers::PACMod3::SteerCmdMsg::CAN_ID = 0x12C;
00027 const int64_t AS::Drivers::PACMod3::TurnSignalCmdMsg::CAN_ID = 0x130;
00028 const int64_t AS::Drivers::PACMod3::WiperCmdMsg::CAN_ID = 0x134;
00029 
00030 // System Reports
00031 const int64_t AS::Drivers::PACMod3::AccelRptMsg::CAN_ID = 0x200;
00032 const int64_t AS::Drivers::PACMod3::BrakeRptMsg::CAN_ID = 0x204;
00033 const int64_t AS::Drivers::PACMod3::CruiseControlButtonsRptMsg::CAN_ID = 0x208;
00034 const int64_t AS::Drivers::PACMod3::DashControlsLeftRptMsg::CAN_ID = 0x20C;
00035 const int64_t AS::Drivers::PACMod3::DashControlsRightRptMsg::CAN_ID = 0x210;
00036 const int64_t AS::Drivers::PACMod3::HazardLightRptMsg::CAN_ID = 0x214;
00037 const int64_t AS::Drivers::PACMod3::HeadlightRptMsg::CAN_ID = 0x218;
00038 const int64_t AS::Drivers::PACMod3::HornRptMsg::CAN_ID = 0x21C;
00039 const int64_t AS::Drivers::PACMod3::MediaControlsRptMsg::CAN_ID = 0x220;
00040 const int64_t AS::Drivers::PACMod3::ParkingBrakeRptMsg::CAN_ID = 0x224;
00041 const int64_t AS::Drivers::PACMod3::ShiftRptMsg::CAN_ID = 0x228;
00042 const int64_t AS::Drivers::PACMod3::SteerRptMsg::CAN_ID = 0x22C;
00043 const int64_t AS::Drivers::PACMod3::TurnSignalRptMsg::CAN_ID = 0x230;
00044 const int64_t AS::Drivers::PACMod3::WiperRptMsg::CAN_ID = 0x234;
00045 
00046 // System Aux Reports
00047 const int64_t AS::Drivers::PACMod3::AccelAuxRptMsg::CAN_ID = 0x300;
00048 const int64_t AS::Drivers::PACMod3::BrakeAuxRptMsg::CAN_ID = 0x304;
00049 const int64_t AS::Drivers::PACMod3::HeadlightAuxRptMsg::CAN_ID = 0x318;
00050 const int64_t AS::Drivers::PACMod3::ShiftAuxRptMsg::CAN_ID = 0x328;
00051 const int64_t AS::Drivers::PACMod3::SteerAuxRptMsg::CAN_ID = 0x32C;
00052 const int64_t AS::Drivers::PACMod3::TurnAuxRptMsg::CAN_ID = 0x330;
00053 const int64_t AS::Drivers::PACMod3::WiperAuxRptMsg::CAN_ID = 0x334;
00054 
00055 // Misc. Reports
00056 const int64_t AS::Drivers::PACMod3::VehicleSpeedRptMsg::CAN_ID = 0x400;
00057 const int64_t AS::Drivers::PACMod3::BrakeMotorRpt1Msg::CAN_ID = 0x401;
00058 const int64_t AS::Drivers::PACMod3::BrakeMotorRpt2Msg::CAN_ID = 0x402;
00059 const int64_t AS::Drivers::PACMod3::BrakeMotorRpt3Msg::CAN_ID = 0x403;
00060 const int64_t AS::Drivers::PACMod3::SteerMotorRpt1Msg::CAN_ID = 0x404;
00061 const int64_t AS::Drivers::PACMod3::SteerMotorRpt2Msg::CAN_ID = 0x405;
00062 const int64_t AS::Drivers::PACMod3::SteerMotorRpt3Msg::CAN_ID = 0x406;
00063 const int64_t AS::Drivers::PACMod3::WheelSpeedRptMsg::CAN_ID = 0x407;
00064 const int64_t AS::Drivers::PACMod3::SteeringPIDRpt1Msg::CAN_ID = 0x408;
00065 const int64_t AS::Drivers::PACMod3::SteeringPIDRpt2Msg::CAN_ID = 0x409;
00066 const int64_t AS::Drivers::PACMod3::SteeringPIDRpt3Msg::CAN_ID = 0x40A;
00067 const int64_t AS::Drivers::PACMod3::YawRateRptMsg::CAN_ID = 0x40D;
00068 const int64_t AS::Drivers::PACMod3::LatLonHeadingRptMsg::CAN_ID = 0x40E;
00069 const int64_t AS::Drivers::PACMod3::DateTimeRptMsg::CAN_ID = 0x40F;
00070 const int64_t AS::Drivers::PACMod3::SteeringPIDRpt4Msg::CAN_ID = 0x410;
00071 const int64_t AS::Drivers::PACMod3::DetectedObjectRptMsg::CAN_ID = 0x411;
00072 const int64_t AS::Drivers::PACMod3::VehicleSpecificRpt1Msg::CAN_ID = 0x412;
00073 const int64_t AS::Drivers::PACMod3::VehicleDynamicsRptMsg::CAN_ID = 0x413;
00074 const int64_t AS::Drivers::PACMod3::VinRptMsg::CAN_ID = 0x414;
00075 const int64_t AS::Drivers::PACMod3::OccupancyRptMsg::CAN_ID = 0x415;
00076 const int64_t AS::Drivers::PACMod3::InteriorLightsRptMsg::CAN_ID = 0x416;
00077 const int64_t AS::Drivers::PACMod3::DoorRptMsg::CAN_ID = 0x417;
00078 const int64_t AS::Drivers::PACMod3::RearLightsRptMsg::CAN_ID = 0x418;
00079 
00080 std::shared_ptr<Pacmod3TxMsg> Pacmod3TxMsg::make_message(const int64_t& can_id)
00081 {
00082   switch (can_id)
00083   {
00084     case AccelRptMsg::CAN_ID:
00085       return std::shared_ptr<Pacmod3TxMsg>(new AccelRptMsg);
00086       break;
00087     case BrakeMotorRpt1Msg::CAN_ID:
00088       return std::shared_ptr<Pacmod3TxMsg>(new BrakeMotorRpt1Msg);
00089       break;
00090     case BrakeMotorRpt2Msg::CAN_ID:
00091       return std::shared_ptr<Pacmod3TxMsg>(new BrakeMotorRpt2Msg);
00092       break;
00093     case BrakeMotorRpt3Msg::CAN_ID:
00094       return std::shared_ptr<Pacmod3TxMsg>(new BrakeMotorRpt3Msg);
00095       break;
00096     case BrakeRptMsg::CAN_ID:
00097       return std::shared_ptr<Pacmod3TxMsg>(new BrakeRptMsg);
00098       break;
00099     case CruiseControlButtonsRptMsg::CAN_ID:
00100       return std::shared_ptr<Pacmod3TxMsg>(new CruiseControlButtonsRptMsg);
00101       break;
00102     case DashControlsLeftRptMsg::CAN_ID:
00103       return std::shared_ptr<Pacmod3TxMsg>(new DashControlsLeftRptMsg);
00104       break;
00105     case DashControlsRightRptMsg::CAN_ID:
00106       return std::shared_ptr<Pacmod3TxMsg>(new DashControlsRightRptMsg);
00107       break;
00108     case DateTimeRptMsg::CAN_ID:
00109       return std::shared_ptr<Pacmod3TxMsg>(new DateTimeRptMsg);
00110       break;
00111     case DetectedObjectRptMsg::CAN_ID:
00112       return std::shared_ptr<Pacmod3TxMsg>(new DetectedObjectRptMsg);
00113       break;      
00114     case DoorRptMsg::CAN_ID:
00115       return std::shared_ptr<Pacmod3TxMsg>(new DoorRptMsg);
00116       break;
00117     case GlobalRptMsg::CAN_ID:
00118       return std::shared_ptr<Pacmod3TxMsg>(new GlobalRptMsg);
00119       break;
00120     case HeadlightRptMsg::CAN_ID:
00121       return std::shared_ptr<Pacmod3TxMsg>(new HeadlightRptMsg);
00122       break;
00123     case HornRptMsg::CAN_ID:
00124       return std::shared_ptr<Pacmod3TxMsg>(new HornRptMsg);
00125       break;
00126     case InteriorLightsRptMsg::CAN_ID:
00127       return std::shared_ptr<Pacmod3TxMsg>(new InteriorLightsRptMsg);
00128       break;
00129     case LatLonHeadingRptMsg::CAN_ID:
00130       return std::shared_ptr<Pacmod3TxMsg>(new LatLonHeadingRptMsg);
00131       break;
00132     case MediaControlsRptMsg::CAN_ID:
00133       return std::shared_ptr<Pacmod3TxMsg>(new MediaControlsRptMsg);
00134       break;
00135     case OccupancyRptMsg::CAN_ID:
00136       return std::shared_ptr<Pacmod3TxMsg>(new OccupancyRptMsg);
00137       break;
00138     case ParkingBrakeRptMsg::CAN_ID:
00139       return std::shared_ptr<Pacmod3TxMsg>(new ParkingBrakeRptMsg);
00140       break;
00141     case RearLightsRptMsg::CAN_ID:
00142       return std::shared_ptr<Pacmod3TxMsg>(new RearLightsRptMsg);
00143       break;
00144     case ShiftRptMsg::CAN_ID:
00145       return std::shared_ptr<Pacmod3TxMsg>(new ShiftRptMsg);
00146       break;
00147     case SteeringPIDRpt1Msg::CAN_ID:
00148       return std::shared_ptr<Pacmod3TxMsg>(new SteeringPIDRpt1Msg);
00149       break;
00150     case SteeringPIDRpt2Msg::CAN_ID:
00151       return std::shared_ptr<Pacmod3TxMsg>(new SteeringPIDRpt2Msg);
00152       break;
00153     case SteeringPIDRpt3Msg::CAN_ID:
00154       return std::shared_ptr<Pacmod3TxMsg>(new SteeringPIDRpt3Msg);
00155       break;
00156     case SteeringPIDRpt4Msg::CAN_ID:
00157       return std::shared_ptr<Pacmod3TxMsg>(new SteeringPIDRpt4Msg);
00158       break;
00159     case SteerMotorRpt1Msg::CAN_ID:
00160       return std::shared_ptr<Pacmod3TxMsg>(new SteerMotorRpt1Msg);
00161       break;
00162     case SteerMotorRpt2Msg::CAN_ID:
00163       return std::shared_ptr<Pacmod3TxMsg>(new SteerMotorRpt2Msg);
00164       break;
00165     case SteerMotorRpt3Msg::CAN_ID:
00166       return std::shared_ptr<Pacmod3TxMsg>(new SteerMotorRpt3Msg);
00167       break;
00168     case SteerRptMsg::CAN_ID:
00169       return std::shared_ptr<Pacmod3TxMsg>(new SteerRptMsg);
00170       break;
00171     case TurnSignalRptMsg::CAN_ID:
00172       return std::shared_ptr<Pacmod3TxMsg>(new TurnSignalRptMsg);
00173       break;
00174     case VehicleSpecificRpt1Msg::CAN_ID:
00175       return std::shared_ptr<Pacmod3TxMsg>(new VehicleSpecificRpt1Msg);
00176       break;      
00177     case VehicleDynamicsRptMsg::CAN_ID:
00178       return std::shared_ptr<Pacmod3TxMsg>(new VehicleDynamicsRptMsg);
00179       break;      
00180     case VehicleSpeedRptMsg::CAN_ID:
00181       return std::shared_ptr<Pacmod3TxMsg>(new VehicleSpeedRptMsg);
00182       break;
00183     case VinRptMsg::CAN_ID:
00184       return std::shared_ptr<Pacmod3TxMsg>(new VinRptMsg);
00185       break;
00186     case WheelSpeedRptMsg::CAN_ID:
00187       return std::shared_ptr<Pacmod3TxMsg>(new WheelSpeedRptMsg);
00188       break;
00189     case WiperRptMsg::CAN_ID:
00190       return std::shared_ptr<Pacmod3TxMsg>(new WiperRptMsg);
00191       break;
00192     case YawRateRptMsg::CAN_ID:
00193       return std::shared_ptr<Pacmod3TxMsg>(new YawRateRptMsg);
00194       break;
00195     case AccelAuxRptMsg::CAN_ID:
00196       return std::shared_ptr<Pacmod3TxMsg>(new AccelAuxRptMsg);
00197       break;
00198     case BrakeAuxRptMsg::CAN_ID:
00199       return std::shared_ptr<Pacmod3TxMsg>(new BrakeAuxRptMsg);
00200       break;
00201     case HeadlightAuxRptMsg::CAN_ID:
00202       return std::shared_ptr<Pacmod3TxMsg>(new HeadlightAuxRptMsg);
00203       break;
00204     case ShiftAuxRptMsg::CAN_ID:
00205       return std::shared_ptr<Pacmod3TxMsg>(new ShiftAuxRptMsg);
00206       break;
00207     case SteerAuxRptMsg::CAN_ID:
00208       return std::shared_ptr<Pacmod3TxMsg>(new SteerAuxRptMsg);
00209       break;
00210     case TurnAuxRptMsg::CAN_ID:
00211       return std::shared_ptr<Pacmod3TxMsg>(new TurnAuxRptMsg);
00212       break;
00213     case WiperAuxRptMsg::CAN_ID:
00214       return std::shared_ptr<Pacmod3TxMsg>(new WiperAuxRptMsg);
00215       break;
00216     default:
00217       return NULL;
00218   }
00219 }
00220 
00221 bool Pacmod3TxMsg::isSystem()
00222 {
00223   return false;
00224 }
00225 
00226 SystemRptMsg::SystemRptMsg() :
00227   Pacmod3TxMsg(),
00228   enabled(false),
00229   override_active(false),
00230   command_output_fault(false),
00231   input_output_fault(false),
00232   output_reported_fault(false),
00233   pacmod_fault(false),
00234   vehicle_fault(false)
00235 {}
00236 
00237 bool SystemRptMsg::isSystem()
00238 {
00239   return true;
00240 }
00241 
00242 SystemRptBoolMsg::SystemRptBoolMsg() :
00243   SystemRptMsg(),
00244   manual_input(false),
00245   command(false),
00246   output(false)
00247 {}
00248 
00249 SystemRptIntMsg::SystemRptIntMsg() :
00250   SystemRptMsg(),
00251   manual_input(0),
00252   command(0),
00253   output(0)
00254 {}
00255 
00256 SystemRptFloatMsg::SystemRptFloatMsg() :
00257   SystemRptMsg(),
00258   manual_input(0),
00259   command(0),
00260   output(0)
00261 {}
00262 
00263 // TX Messages
00264 void GlobalRptMsg::parse(uint8_t *in)
00265 {
00266   enabled = in[0] & 0x01;
00267   override_active = ((in[0] & 0x02) > 0);
00268   fault_active = ((in[0] & 0x80) > 0);
00269   config_fault_active = ((in[1] & 0x01) > 0);
00270   user_can_timeout = ((in[0] & 0x04) > 0);
00271   steering_can_timeout = ((in[0] & 0x08) > 0);
00272   brake_can_timeout = ((in[0] & 0x10) > 0);
00273   subsystem_can_timeout = ((in[0] & 0x20) > 0);
00274   vehicle_can_timeout = ((in[0] & 0x40) > 0);
00275   user_can_read_errors = ((in[6] << 8) | in[7]);
00276 }
00277 
00278 void SystemRptBoolMsg::parse(uint8_t *in)
00279 {
00280   enabled = ((in[0] & 0x01) > 0);
00281   override_active = ((in[0] & 0x02) > 0);
00282   command_output_fault = ((in[0] & 0x04) > 0);
00283   input_output_fault = ((in[0] & 0x08) > 0);
00284   output_reported_fault = ((in[0] & 0x10) > 0);
00285   pacmod_fault = ((in[0] & 0x20) > 0);
00286   vehicle_fault = ((in[0] & 0x40) > 0);
00287 
00288   manual_input = ((in[1] & 0x01) > 0);
00289   command = ((in[2] & 0x01) > 0);
00290   output = ((in[3] & 0x01) > 0);
00291 }
00292 
00293 void SystemRptIntMsg::parse(uint8_t *in)
00294 {
00295   enabled = ((in[0] & 0x01) > 0);
00296   override_active = ((in[0] & 0x02) > 0);
00297   command_output_fault = ((in[0] & 0x04) > 0);
00298   input_output_fault = ((in[0] & 0x08) > 0);
00299   output_reported_fault = ((in[0] & 0x10) > 0);
00300   pacmod_fault = ((in[0] & 0x20) > 0);
00301   vehicle_fault = ((in[0] & 0x40) > 0);
00302 
00303   manual_input = in[1];
00304   command = in[2];
00305   output = in[3];
00306 }
00307 
00308 void SystemRptFloatMsg::parse(uint8_t *in)
00309 {
00310   enabled = ((in[0] & 0x01) > 0);
00311   override_active = ((in[0] & 0x02) > 0);
00312   command_output_fault = ((in[0] & 0x04) > 0);
00313   input_output_fault = ((in[0] & 0x08) > 0);
00314   output_reported_fault = ((in[0] & 0x10) > 0);
00315   pacmod_fault = ((in[0] & 0x20) > 0);
00316   vehicle_fault = ((in[0] & 0x40) > 0);
00317 
00318   int16_t temp;
00319 
00320   temp = ((int16_t)in[1] << 8) | in[2];
00321   manual_input = (double)(temp / 1000.0);
00322 
00323   temp = ((int16_t)in[3] << 8) | in[4];
00324   command = (double)(temp / 1000.0);
00325 
00326   temp = ((int16_t)in[5] << 8) | in[6];
00327   output = (double)(temp / 1000.0);
00328 }
00329 
00330 void AccelAuxRptMsg::parse(uint8_t *in)
00331 {
00332   int16_t temp;
00333 
00334   temp = ((int16_t)in[0] << 8) | in[1];
00335   raw_pedal_pos = (float)temp / 1000.0;
00336 
00337   temp = ((int16_t)in[2] << 8) | in[3];
00338   raw_pedal_force = (float)temp / 1000.0;
00339 
00340   user_interaction = (in[4] & 0x01) > 0;
00341   raw_pedal_pos_is_valid = (in[5] & 0x01) > 0;
00342   raw_pedal_force_is_valid = (in[5] & 0x02) > 0;
00343   user_interaction_is_valid = (in[5] & 0x04) > 0;
00344 }
00345 
00346 void BrakeAuxRptMsg::parse(uint8_t *in)
00347 {
00348   int16_t temp;
00349 
00350   temp = ((int16_t)in[0] << 8) | in[1];
00351   raw_pedal_pos = (float)temp / 1000.0;
00352 
00353   temp = ((int16_t)in[2] << 8) | in[3];
00354   raw_pedal_force = (float)temp / 1000.0;
00355 
00356   temp = ((int16_t)in[4] << 8) | in[5];
00357   raw_brake_pressure = (float)temp / 1000.0;
00358 
00359   user_interaction = (in[6] & 0x01) > 0;
00360   brake_on_off = (in[6] & 0x02) > 0;
00361   raw_pedal_pos_is_valid = (in[7] & 0x01) > 0;
00362   raw_pedal_force_is_valid = (in[7] & 0x02) > 0;
00363   raw_brake_pressure_is_valid = (in[7] & 0x04) > 0;
00364   user_interaction_is_valid = (in[7] & 0x08) > 0;
00365   brake_on_off_is_valid = (in[7] & 0x10) > 0;
00366 }
00367 
00368 void DateTimeRptMsg::parse(uint8_t *in)
00369 {
00370   year = in[0];
00371   month = in[1];
00372   day = in[2];
00373   hour = in[3];
00374   minute = in[4];
00375   second = in[5];
00376 }
00377 
00378 void DetectedObjectRptMsg::parse(uint8_t *in)
00379 {
00380   int16_t temp;
00381   
00382   temp = (((int16_t)in[0] << 8) | in[1]);
00383   front_object_distance_low_res = (double)(temp / 1000.0);
00384   
00385   temp = (((int16_t)in[2] << 8) | in[3]);
00386   front_object_distance_high_res = (double)(temp / 1000.0);
00387 }
00388 
00389 void DoorRptMsg::parse(uint8_t *in)
00390 {
00391   driver_door_open = ((in[0] & 0x01) > 0);
00392   driver_door_open_is_valid = ((in[1] & 0x01) > 0);
00393   passenger_door_open = ((in[0] & 0x02) > 0);
00394   passenger_door_open_is_valid = ((in[1] & 0x02) > 0);
00395   rear_driver_door_open = ((in[0] & 0x04) > 0);
00396   rear_driver_door_open_is_valid = ((in[1] & 0x04) > 0);
00397   rear_passenger_door_open = ((in[0] & 0x08) > 0);
00398   rear_passenger_door_open_is_valid = ((in[1] & 0x08) > 0);
00399   hood_open = ((in[0] & 0x10) > 0);
00400   hood_open_is_valid = ((in[1] & 0x10) > 0);
00401   trunk_open = ((in[0] & 0x20) > 0);
00402   trunk_open_is_valid = ((in[1] & 0x20) > 0);
00403   fuel_door_open = ((in[0] & 0x40) > 0);
00404   fuel_door_open_is_valid = ((in[1] & 0x40) > 0);
00405 }
00406 
00407 void HeadlightAuxRptMsg::parse(uint8_t *in)
00408 {
00409   headlights_on = (in[0] & 0x01) > 0;
00410   headlights_on_bright = (in[0] & 0x02) > 0;
00411   fog_lights_on = (in[0] & 0x04) > 0;
00412   headlights_mode = in[1];
00413   headlights_on_is_valid = (in[2] & 0x01) > 0;
00414   headlights_on_bright_is_valid = (in[2] & 0x02) > 0;
00415   fog_lights_on = (in[2] & 0x04) > 0;
00416   headlights_mode_is_valid = (in[2] & 0x08) > 0;
00417 }
00418 
00419 void InteriorLightsRptMsg::parse(uint8_t *in)
00420 {
00421   front_dome_lights_on = ((in[0] & 0x01) > 0);
00422   front_dome_lights_on_is_valid = ((in[2] & 0x01) > 0);
00423   rear_dome_lights_on = ((in[0] & 0x02) > 0);
00424   rear_dome_lights_on_is_valid = ((in[2] & 0x02) > 0);
00425   mood_lights_on = ((in[0] & 0x04) > 0);
00426   mood_lights_on_is_valid = ((in[2] & 0x04) > 0);
00427   dim_level = (DimLevel)in[1];
00428   dim_level_is_valid = ((in[2] & 0x08) > 0);
00429 }
00430 
00431 void LatLonHeadingRptMsg::parse(uint8_t *in)
00432 {
00433   latitude_degrees = (int8_t)in[0];
00434   latitude_minutes = (uint8_t)in[1];
00435   latitude_seconds = (uint8_t)in[2];
00436   longitude_degrees = (int8_t)in[3];
00437   longitude_minutes = (uint8_t)in[4];
00438   longitude_seconds = (uint8_t)in[5];
00439   heading = (((int16_t)in[6] << 8) | in[7]) / 100.0;
00440 }
00441 
00442 void MotorRpt1Msg::parse(uint8_t *in)
00443 {
00444   int32_t temp;
00445 
00446   temp = ((int32_t)in[0] << 24) | ((int32_t)in[1] << 16) | ((int32_t)in[2] << 8) | in[3];
00447   current = (double)(temp / 1000.0);
00448   
00449   temp = ((int32_t)in[4] << 24) | ((int32_t)in[5] << 16) | ((int32_t)in[6] << 8) | in[7];
00450   position = (double)(temp / 1000.0);
00451 }
00452 
00453 void MotorRpt2Msg::parse(uint8_t *in)
00454 {
00455   int16_t temp16;
00456   int32_t temp32;
00457 
00458   temp16 = ((int16_t)in[0] << 8) | in[1];
00459   encoder_temp = (double)temp16;
00460 
00461   temp16 = ((int16_t)in[2] << 8) | in[3];
00462   motor_temp = (double)temp16;
00463 
00464   temp32 = ((int32_t)in[7] << 24) | ((int32_t)in[6] << 16) | ((int32_t)in[5] << 8) | in[4];
00465   velocity = (double)(temp32 / 1000.0);
00466 }
00467 
00468 void MotorRpt3Msg::parse(uint8_t *in)
00469 {
00470   int32_t temp;
00471 
00472   temp = ((int32_t)in[0] << 24) | ((int32_t)in[1] << 16) | ((int32_t)in[2] << 8) | in[3];
00473   torque_output = (double)(temp / 1000.0);
00474 
00475   temp = ((int32_t)in[4] << 24) | ((int32_t)in[5] << 16) | ((int32_t)in[6] << 8) | in[7];
00476   torque_input = (double)(temp / 1000.0);
00477 }
00478 
00479 void OccupancyRptMsg::parse(uint8_t *in)
00480 {
00481   driver_seat_occupied = ((in[0] & 0x01) > 0);
00482   driver_seat_occupied_is_valid = ((in[1] & 0x01) > 0);
00483   passenger_seat_occupied = ((in[0] & 0x02) > 0);
00484   passenger_seat_occupied_is_valid = ((in[1] & 0x02) > 0);
00485   rear_seat_occupied = ((in[0] & 0x04) > 0);
00486   rear_seat_occupied_is_valid = ((in[1] & 0x04) > 0);
00487   driver_seatbelt_buckled = ((in[0] & 0x08) > 0);
00488   driver_seatbelt_buckled_is_valid = ((in[1] & 0x08) > 0);
00489   passenger_seatbelt_buckled = ((in[0] & 0x10) > 0);
00490   passenger_seatbelt_buckled_is_valid = ((in[1] & 0x10) > 0);
00491   rear_seatbelt_buckled = ((in[0] & 0x20) > 0);
00492   rear_seatbelt_buckled_is_valid = ((in[1] & 0x20) > 0);
00493 }
00494 
00495 void RearLightsRptMsg::parse(uint8_t *in)
00496 {
00497   brake_lights_on = ((in[0] & 0x01) > 0);
00498   brake_lights_on_is_valid = ((in[1] & 0x01) > 0);
00499   reverse_lights_on = ((in[0] & 0x02) > 0);
00500   reverse_lights_on_is_valid = ((in[1] & 0x02) > 0);
00501 }
00502 
00503 void ShiftAuxRptMsg::parse(uint8_t *in)
00504 {
00505   between_gears = (in[0] & 0x01) > 0;
00506   stay_in_neutral_mode = (in[0] & 0x02) > 0;
00507   brake_interlock_active = (in[0] & 0x04) > 0;
00508   speed_interlock_active = (in[0] & 0x08) > 0;
00509   between_gears_is_valid = (in[1] & 0x01) > 0;
00510   stay_in_neutral_mode_is_valid = (in[1] & 0x02) > 0;
00511   brake_interlock_active_is_valid = (in[1] & 0x04) > 0;
00512   speed_interlock_active_is_valid = (in[1] & 0x08) > 0;
00513 }
00514 
00515 void SteerAuxRptMsg::parse(uint8_t *in)
00516 {
00517   int16_t temp;
00518 
00519   temp = ((int16_t)in[0] << 8) | in[1];
00520   raw_position = (float)temp / 10.0;
00521 
00522   temp = ((int16_t)in[2] << 8) | in[3];
00523   raw_torque = (float)temp / 10.0;
00524 
00525   uint16_t temp2;
00526 
00527   temp2 = ((uint16_t)in[4] << 8) | in[5];
00528   rotation_rate = (float)temp2 / 100.0;
00529 
00530   user_interaction = (in[6] & 0x01) > 0;
00531   raw_position_is_valid = (in[7] & 0x01) > 0;
00532   raw_torque_is_valid = (in[7] & 0x02) > 0;
00533   rotation_rate_is_valid = (in[7] & 0x04) > 0;
00534   user_interaction_is_valid = (in[7] & 0x08) > 0;
00535 }
00536 
00537 void SteeringPIDRpt1Msg::parse(uint8_t *in)
00538 {
00539   int16_t temp;
00540 
00541   temp = ((int16_t)in[0] << 8) | in[1];
00542   dt = (double)(temp / 1000.0);
00543 
00544   temp = ((int16_t)in[2] << 8) | in[3];
00545   Kp = (double)(temp / 1000.0);
00546 
00547   temp = ((int16_t)in[4] << 8) | in[5];
00548   Ki = (double)(temp / 1000.0);
00549 
00550   temp = ((int16_t)in[6] << 8) | in[7];
00551   Kd = (double)(temp / 1000.0);
00552 }
00553 
00554 void SteeringPIDRpt2Msg::parse(uint8_t *in)
00555 {
00556   int16_t temp;
00557 
00558   temp = ((int16_t)in[0] << 8) | in[1];
00559   P_term = (double)(temp / 1000.0);
00560 
00561   temp = ((int16_t)in[2] << 8) | in[3];
00562   I_term = (double)(temp / 1000.0);
00563 
00564   temp = ((int16_t)in[4] << 8) | in[5];
00565   D_term = (double)(temp / 1000.0);
00566 
00567   temp = ((int16_t)in[6] << 8) | in[7];
00568   all_terms = (double)(temp / 1000.0);
00569 }
00570 
00571 void SteeringPIDRpt3Msg::parse(uint8_t *in)
00572 {
00573   int16_t temp;
00574 
00575   temp = ((int16_t)in[0] << 8) | in[1];
00576   new_torque = (double)(temp / 1000.0);
00577 
00578   temp = ((int16_t)in[2] << 8) | in[3];
00579   str_angle_desired = (double)(temp / 1000.0);
00580 
00581   temp = ((int16_t)in[4] << 8) | in[5];
00582   str_angle_actual = (double)(temp / 1000.0);
00583 
00584   temp = ((int16_t)in[6] << 8) | in[7];
00585   error = (double)(temp / 1000.0);
00586 }
00587 
00588 void SteeringPIDRpt4Msg::parse(uint8_t *in)
00589 {
00590   int16_t temp;
00591 
00592   temp = ((int16_t)in[0] << 8) | in[1];
00593   angular_velocity = (double)(temp / 1000.0);
00594 
00595   temp = ((int16_t)in[2] << 8) | in[3];
00596   angular_acceleration = (double)(temp / 1000.0);
00597 }
00598 
00599 void TurnAuxRptMsg::parse(uint8_t *in)
00600 {
00601   driver_blinker_bulb_on = (in[0] & 0x01) > 0;
00602   passenger_blinker_bulb_on = (in[0] & 0x02) > 0;
00603   driver_blinker_bulb_on_is_valid = (in[1] & 0x01) > 0;
00604   passenger_blinker_bulb_on_is_valid = (in[1] & 0x02) > 0;
00605 }
00606 
00607 void VehicleSpecificRpt1Msg::parse(uint8_t *in)
00608 {
00609   shift_pos_1 = in[0];
00610   shift_pos_2 = in[1];
00611 }
00612 
00613 void VehicleDynamicsRptMsg::parse(uint8_t *in)
00614 {
00615   int16_t temp;
00616   
00617   temp = (((int16_t)in[1] << 8) | in[2]);
00618   brake_torque = (double)(temp / 1000.0);
00619   
00620   g_forces = in[0];
00621 }
00622 
00623 void VehicleSpeedRptMsg::parse(uint8_t *in)
00624 {
00625   int16_t temp;
00626 
00627   temp = ((int16_t)in[0] << 8) | in[1];
00628   vehicle_speed = (double)(temp / 100.0);
00629 
00630   vehicle_speed_valid = (in[2] == 1);
00631   vehicle_speed_raw[0] = in[3];
00632   vehicle_speed_raw[1] = in[4];
00633 }
00634 
00635 void VinRptMsg::parse(uint8_t *in)
00636 {
00637   std::ostringstream oss;
00638   oss << in[0] << in[1] << in[2];
00639   mfg_code = oss.str();
00640 
00641   if (mfg_code == "52C")
00642     mfg = "POLARIS INDUSTRIES INC.";
00643   else if (mfg_code == "3HS")
00644     mfg = "NAVISTAR, INC.";
00645   else if (mfg_code == "2T2")
00646     mfg = "TOYOTA MOTOR MANUFACTURING CANADA";
00647   else
00648     mfg = "UNKNOWN";
00649 
00650   model_year_code = in[3];
00651 
00652   if (model_year_code >= '1' && model_year_code <= '9')
00653   {
00654     model_year = 2000 + model_year_code;
00655   }
00656   else if (model_year_code >= 'A' && model_year_code < 'Z')
00657   {
00658     switch (model_year_code)
00659     {
00660       case 'A':
00661         model_year = 2010;
00662         break;
00663       case 'B':
00664         model_year = 2011;
00665         break;
00666       case 'C':
00667         model_year = 2012;
00668         break;
00669       case 'D':
00670         model_year = 2013;
00671         break;
00672       case 'E':
00673         model_year = 2014;
00674         break;
00675       case 'F':
00676         model_year = 2015;
00677         break;
00678       case 'G':
00679         model_year = 2016;
00680         break;
00681       case 'H':
00682         model_year = 2017;
00683         break;
00684       case 'J':
00685         model_year = 2018;
00686         break;
00687       case 'K':
00688         model_year = 2019;
00689         break;
00690       case 'L':
00691         model_year = 2020;
00692         break;
00693       case 'M':
00694         model_year = 2021;
00695         break;
00696       case 'N':
00697         model_year = 2022;
00698         break;
00699       case 'P':
00700         model_year = 2023;
00701         break;
00702       case 'R':
00703         model_year = 2024;
00704         break;
00705       case 'S':
00706         model_year = 2025;
00707         break;
00708       case 'T':
00709         model_year = 2026;
00710         break;
00711       case 'V':
00712         model_year = 2027;
00713         break;
00714       case 'W':
00715         model_year = 2028;
00716         break;
00717       case 'X':
00718         model_year = 2029;
00719         break;
00720       case 'Y':
00721         model_year = 2030;
00722         break;
00723       default:
00724         model_year = 9999;
00725     }
00726   }
00727   else
00728   {
00729     model_year = 9999;
00730   }
00731 
00732   serial = (in[4] & 0x0F);
00733   serial = (serial << 8) | in[5];
00734   serial = (serial << 8) | in[6];
00735 }
00736 
00737 void WheelSpeedRptMsg::parse(uint8_t *in)
00738 {
00739   int16_t temp;
00740 
00741   temp = ((int16_t)in[0] << 8) | in[1];
00742   front_left_wheel_speed = (double)(temp / 100.0);
00743 
00744   temp = ((int16_t)in[2] << 8) | in[3];
00745   front_right_wheel_speed = (double)(temp / 100.0);
00746 
00747   temp = ((int16_t)in[4] << 8) | in[5];
00748   rear_left_wheel_speed = (double)(temp / 100.0);
00749 
00750   temp = ((int16_t)in[6] << 8) | in[7];
00751   rear_right_wheel_speed = (double)(temp / 100.0);
00752 }
00753 
00754 void WiperAuxRptMsg::parse(uint8_t *in)
00755 {
00756   front_wiping = (in[0] & 0x01) > 0;
00757   front_spraying = (in[0] & 0x02) > 0;
00758   rear_wiping = (in[0] & 0x04) > 0;
00759   rear_spraying = (in[0] & 0x08) > 0;
00760   spray_near_empty = (in[0] & 0x10) > 0;
00761   spray_empty = (in[0] & 0x20) > 0;
00762   front_wiping_is_valid = (in[1] & 0x01) > 0;
00763   front_spraying_is_valid = (in[1] & 0x02) > 0;
00764   rear_wiping_is_valid = (in[1] & 0x04) > 0;
00765   rear_spraying_is_valid = (in[1] & 0x08) > 0;
00766   spray_near_empty_is_valid = (in[1] & 0x10) > 0;
00767   spray_empty_is_valid = (in[1] & 0x20) > 0;
00768 }
00769 
00770 void YawRateRptMsg::parse(uint8_t *in)
00771 {
00772   int16_t temp;
00773   
00774   temp = ((int16_t)in[0] << 8) | in[1];
00775   yaw_rate = (double)(temp / 100.0);
00776 }
00777 
00778 // RX Messages
00779 void SystemCmdBool::encode(bool enable,
00780                            bool ignore_overrides,
00781                            bool clear_override,
00782                            bool cmd)
00783 {
00784   data.assign(8, 0);
00785 
00786   data[0] = (enable ? 0x01 : 0x00);
00787   data[0] |= (ignore_overrides ? 0x02 : 0x00);
00788   data[0] |= clear_override ? 0x04 : 0x00;
00789   data[1] = (cmd ? 0x01 : 0x00);
00790 }
00791 
00792 void SystemCmdFloat::encode(bool enable,
00793                             bool ignore_overrides,
00794                             bool clear_override,
00795                             float cmd)
00796 {
00797   data.assign(8, 0);
00798 
00799   data[0] = enable ? 0x01 : 0x00;
00800   data[0] |= ignore_overrides ? 0x02 : 0x00;
00801   data[0] |= clear_override ? 0x04 : 0x00;
00802 
00803   uint16_t cmd_float = (uint16_t)(cmd * 1000.0);
00804   data[1] = (cmd_float & 0xFF00) >> 8;
00805   data[2] = cmd_float & 0x00FF;
00806 }
00807 
00808 void SystemCmdInt::encode(bool enable,
00809                           bool ignore_overrides,
00810                           bool clear_override,
00811                           uint8_t cmd)
00812 {
00813   data.assign(8, 0);
00814 
00815   data[0] = enable ? 0x01 : 0x00;
00816   data[0] |= ignore_overrides ? 0x02 : 0x00;
00817   data[0] |= clear_override ? 0x04 : 0x00;
00818   data[1] = cmd;
00819 }
00820 
00821 void SteerCmdMsg::encode(bool enable,
00822                          bool ignore_overrides,
00823                          bool clear_override,
00824                          float steer_pos,
00825                          float steer_spd)
00826 {
00827   data.assign(8, 0);
00828 
00829   data[0] = enable ? 0x01 : 0x00;
00830   data[0] |= ignore_overrides ? 0x02 : 0x00;
00831   data[0] |= clear_override ? 0x04 : 0x00;
00832 
00833   int16_t raw_pos = (int16_t)(1000.0 * steer_pos);
00834   uint16_t raw_spd = (uint16_t)(1000.0 * steer_spd);
00835 
00836   data[1] = (raw_pos & 0xFF00) >> 8;
00837   data[2] = raw_pos & 0x00FF;
00838   data[3] = (raw_spd & 0xFF00) >> 8;    
00839   data[4] = raw_spd & 0x00FF;
00840 }


pacmod3
Author(s): Joe Driscoll , Josh Whitley
autogenerated on Thu Jun 6 2019 17:34:14