15 #include <unordered_map> 18 #include <std_msgs/Bool.h> 19 #include <std_msgs/Float64.h> 20 #include <can_msgs/Frame.h> 81 std::unordered_map<long long, std::shared_ptr<LockedData>>
rx_list;
90 for (
auto rx_it =
rx_list.begin(); rx_it !=
rx_list.end(); rx_it++)
95 std::vector<uint8_t> current_data = rx_it->second->getData();
98 current_data[0] |= 0x01;
100 current_data[0] &= 0xFE;
102 rx_it->second->setData(current_data);
109 auto rx_it =
rx_list.find(can_id);
114 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
119 auto rx_it =
rx_list.find(can_id);
124 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
129 auto rx_it =
rx_list.find(can_id);
134 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
191 auto rx_it =
rx_list.find(can_id);
196 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
211 void send_can(
long id,
const std::vector<unsigned char>& vec)
213 can_msgs::Frame frame;
215 frame.is_rtr =
false;
216 frame.is_extended =
false;
217 frame.is_error =
false;
219 std::copy(vec.begin(), vec.end(), frame.data.begin());
228 std::vector<unsigned char> data;
230 const std::chrono::milliseconds loop_pause = std::chrono::milliseconds(33);
231 const std::chrono::milliseconds inter_msg_pause = std::chrono::milliseconds(1);
232 bool keep_going =
true;
242 for (
const auto& element :
rx_list)
244 send_can(element.first, element.second->getData());
245 std::this_thread::sleep_for(inter_msg_pause);
248 std::chrono::system_clock::time_point next_time = std::chrono::system_clock::now();
249 next_time += loop_pause;
250 std::this_thread::sleep_until(next_time);
259 void can_read(
const can_msgs::Frame::ConstPtr &msg)
265 if (parser_class != NULL && pub !=
pub_tx_list.end())
267 parser_class->parse(const_cast<unsigned char *>(&msg->data[0]));
268 handler.
fillAndPublish(msg->id,
"pacmod", pub->second, parser_class);
270 if (parser_class->isSystem())
272 auto dc_parser = std::dynamic_pointer_cast<
SystemRptMsg>(parser_class);
275 dc_parser->override_active,
276 (dc_parser->command_output_fault |
277 dc_parser->input_output_fault |
278 dc_parser->output_reported_fault |
279 dc_parser->pacmod_fault |
280 dc_parser->vehicle_fault));
285 auto dc_parser = std::dynamic_pointer_cast<
GlobalRptMsg>(parser_class);
287 std_msgs::Bool bool_pub_msg;
288 bool_pub_msg.data = (dc_parser->enabled);
289 enabled_pub.
publish(bool_pub_msg);
291 if (dc_parser->override_active ||
292 dc_parser->fault_active)
300 std_msgs::Float64 veh_spd_ms_msg;
301 veh_spd_ms_msg.data = (dc_parser->vehicle_speed);
302 vehicle_speed_ms_pub.
publish(veh_spd_ms_msg);
307 int main(
int argc,
char *argv[])
316 std::shared_ptr<ros::Subscriber> wiper_set_cmd_sub,
317 headlight_set_cmd_sub,
319 cruise_control_buttons_set_cmd_sub,
320 dash_controls_left_set_cmd_sub,
321 dash_controls_right_set_cmd_sub,
322 media_controls_set_cmd_sub;
347 ROS_WARN(
"PACMod3 - An invalid vehicle type was entered. Assuming POLARIS_GEM.");
352 can_rx_pub = n.
advertise<can_msgs::Frame>(
"can_rx", 20);
353 global_rpt_pub = n.
advertise<pacmod_msgs::GlobalRpt>(
"parsed_tx/global_rpt", 20);
354 accel_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/accel_rpt", 20);
355 brake_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/brake_rpt", 20);
356 shift_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/shift_rpt", 20);
357 steer_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/steer_rpt", 20);
358 turn_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/turn_rpt", 20);
359 vehicle_speed_pub = n.
advertise<pacmod_msgs::VehicleSpeedRpt>(
"parsed_tx/vehicle_speed_rpt", 20);
360 vin_rpt_pub = n.
advertise<pacmod_msgs::VinRpt>(
"parsed_tx/vin_rpt", 5);
361 accel_aux_rpt_pub = n.
advertise<pacmod_msgs::AccelAuxRpt>(
"parsed_tx/accel_aux_rpt", 20);
362 brake_aux_rpt_pub = n.
advertise<pacmod_msgs::BrakeAuxRpt>(
"parsed_tx/brake_aux_rpt", 20);
363 shift_aux_rpt_pub = n.
advertise<pacmod_msgs::ShiftAuxRpt>(
"parsed_tx/shift_aux_rpt", 20);
364 steer_aux_rpt_pub = n.
advertise<pacmod_msgs::SteerAuxRpt>(
"parsed_tx/steer_aux_rpt", 20);
365 turn_aux_rpt_pub = n.
advertise<pacmod_msgs::TurnAuxRpt>(
"parsed_tx/turn_aux_rpt", 20);
367 enabled_pub = n.
advertise<std_msgs::Bool>(
"as_tx/enabled", 20,
true);
368 vehicle_speed_ms_pub = n.
advertise<std_msgs::Float64>(
"as_tx/vehicle_speed", 20);
369 all_system_statuses_pub = n.
advertise<pacmod_msgs::AllSystemStatuses>(
"as_tx/all_system_statuses", 20);
371 std::string frame_id =
"pacmod";
398 std::shared_ptr<LockedData> accel_data(
new LockedData);
399 std::shared_ptr<LockedData> brake_data(
new LockedData);
400 std::shared_ptr<LockedData> shift_data(
new LockedData);
401 std::shared_ptr<LockedData> steer_data(
new LockedData);
402 std::shared_ptr<LockedData> turn_data(
new LockedData);
414 brake_rpt_detail_1_pub = n.
advertise<pacmod_msgs::MotorRpt1>(
"parsed_tx/brake_rpt_detail_1", 20);
415 brake_rpt_detail_2_pub = n.
advertise<pacmod_msgs::MotorRpt2>(
"parsed_tx/brake_rpt_detail_2", 20);
416 brake_rpt_detail_3_pub = n.
advertise<pacmod_msgs::MotorRpt3>(
"parsed_tx/brake_rpt_detail_3", 20);
417 steering_rpt_detail_1_pub = n.
advertise<pacmod_msgs::MotorRpt1>(
"parsed_tx/steer_rpt_detail_1", 20);
418 steering_rpt_detail_2_pub = n.
advertise<pacmod_msgs::MotorRpt2>(
"parsed_tx/steer_rpt_detail_2", 20);
419 steering_rpt_detail_3_pub = n.
advertise<pacmod_msgs::MotorRpt3>(
"parsed_tx/steer_rpt_detail_3", 20);
431 wiper_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/wiper_rpt", 20);
432 wiper_aux_rpt_pub = n.
advertise<pacmod_msgs::WiperAuxRpt>(
"parsed_tx/wiper_aux_rpt", 20);
439 std::shared_ptr<LockedData> wiper_data(
new LockedData);
446 date_time_rpt_pub = n.
advertise<pacmod_msgs::DateTimeRpt>(
"parsed_tx/date_time_rpt", 20);
447 headlight_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/headlight_rpt", 20);
448 horn_rpt_pub = n.
advertise<pacmod_msgs::SystemRptBool>(
"parsed_tx/horn_rpt", 20);
449 lat_lon_heading_rpt_pub = n.
advertise<pacmod_msgs::LatLonHeadingRpt>(
"parsed_tx/lat_lon_heading_rpt", 20);
450 parking_brake_rpt_pub = n.
advertise<pacmod_msgs::SystemRptBool>(
"parsed_tx/parking_brake_status_rpt", 20);
451 wheel_speed_rpt_pub = n.
advertise<pacmod_msgs::WheelSpeedRpt>(
"parsed_tx/wheel_speed_rpt", 20);
452 yaw_rate_rpt_pub = n.
advertise<pacmod_msgs::YawRateRpt>(
"parsed_tx/yaw_rate_rpt", 20);
453 headlight_aux_rpt_pub = n.
advertise<pacmod_msgs::HeadlightAuxRpt>(
"parsed_tx/headlight_aux_rpt", 20);
467 std::shared_ptr<LockedData> headlight_data(
new LockedData);
468 std::shared_ptr<LockedData> horn_data(
new LockedData);
476 detected_object_rpt_pub = n.
advertise<pacmod_msgs::DetectedObjectRpt>(
"parsed_tx/detected_object_rpt", 20);
477 vehicle_dynamics_rpt_pub = n.
advertise<pacmod_msgs::VehicleDynamicsRpt>(
"parsed_tx/vehicle_dynamics_rpt", 20);
485 steering_pid_rpt_1_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt1>(
"parsed_tx/steer_pid_rpt_1", 20);
486 steering_pid_rpt_2_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt2>(
"parsed_tx/steer_pid_rpt_2", 20);
487 steering_pid_rpt_3_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt3>(
"parsed_tx/steer_pid_rpt_3", 20);
488 steering_pid_rpt_4_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt4>(
"parsed_tx/steer_pid_rpt_4", 20);
502 occupancy_rpt_pub = n.
advertise<pacmod_msgs::OccupancyRpt>(
"parsed_tx/occupancy_rpt", 20);
503 interior_lights_rpt_pub = n.
advertise<pacmod_msgs::InteriorLightsRpt>(
"parsed_tx/interior_lights_rpt", 20);
504 door_rpt_pub = n.
advertise<pacmod_msgs::DoorRpt>(
"parsed_tx/door_rpt", 20);
505 rear_lights_rpt_pub = n.
advertise<pacmod_msgs::RearLightsRpt>(
"parsed_tx/rear_lights_rpt", 20);
533 for (
auto rx_it =
rx_list.begin(); rx_it !=
rx_list.end(); rx_it++)
539 turn_encoder.
encode(
false,
false,
false, pacmod_msgs::SystemCmdInt::TURN_NONE);
540 rx_it->second->setData(turn_encoder.
data);
544 std::vector<uint8_t> empty_vec;
545 empty_vec.assign(8, 0);
546 rx_it->second->setData(empty_vec);
560 pacmod_msgs::AllSystemStatuses ss_msg;
564 pacmod_msgs::KeyValuePair kvp;
567 kvp.key =
"Accelerator";
571 kvp.key =
"Cruise Control Buttons";
573 kvp.key =
"Dash Controls Left";
575 kvp.key =
"Dash Controls Right";
577 kvp.key =
"Hazard Lights";
579 kvp.key =
"Headlights";
583 kvp.key =
"Media Controls";
585 kvp.key =
"Parking Brake";
589 kvp.key =
"Steering";
591 kvp.key =
"Turn Signals";
595 kvp.value = std::get<0>(system->second) ?
"True" :
"False";
597 ss_msg.enabled_status.push_back(kvp);
599 kvp.value = std::get<1>(system->second) ?
"True" :
"False";
601 ss_msg.overridden_status.push_back(kvp);
603 kvp.value = std::get<2>(system->second) ?
"True" :
"False";
605 ss_msg.fault_status.push_back(kvp);
608 all_system_statuses_pub.publish(ss_msg);
620 can_write_thread.join();
void callback_dash_controls_left_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
ros::Publisher interior_lights_rpt_pub
std::map< long long, std::tuple< bool, bool, bool > > system_statuses
void callback_brake_cmd_sub(const pacmod_msgs::SystemCmdFloat::ConstPtr &msg)
void set_enable(bool val)
static const int64_t CAN_ID
void callback_shift_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
void lookup_and_encode(const int64_t &can_id, const pacmod_msgs::SystemCmdBool::ConstPtr &msg)
void encode(bool enable, bool ignore_overrides, bool clear_override, uint8_t cmd)
ros::Publisher headlight_aux_rpt_pub
void callback_headlight_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
void can_read(const can_msgs::Frame::ConstPtr &msg)
void callback_media_controls_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
void publish(const boost::shared_ptr< M > &message) const
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static std::shared_ptr< Pacmod3TxMsg > make_message(const int64_t &can_id)
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher wiper_rpt_pub
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Publisher dash_controls_left_rpt_pub
ros::Publisher steering_pid_rpt_4_pub
Pacmod3TxRosMsgHandler handler
void callback_dash_controls_right_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
ros::Publisher steering_rpt_detail_1_pub
int main(int argc, char *argv[])
static const int64_t CAN_ID
ros::Publisher shift_aux_rpt_pub
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher brake_rpt_pub
ros::Publisher steering_rpt_detail_2_pub
void callback_cruise_control_buttons_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
ros::Publisher steering_rpt_detail_3_pub
void fillAndPublish(const int64_t &can_id, std::string frame_id, ros::Publisher &pub, std::shared_ptr< Pacmod3TxMsg > &parser_class)
ros::Publisher vehicle_specific_rpt_1_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher turn_rpt_pub
ros::Publisher media_controls_rpt_pub
ros::Publisher shift_rpt_pub
ros::Publisher occupancy_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
std::mutex keep_going_mut
ros::Publisher brake_rpt_detail_1_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher accel_aux_rpt_pub
static const int64_t CAN_ID
std::unordered_map< int64_t, ros::Publisher > pub_tx_list
std::string veh_type_string
ros::Publisher rear_lights_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher steer_rpt_pub
ros::Publisher door_rpt_pub
ros::Publisher cruise_control_buttons_rpt_pub
static const int64_t CAN_ID
ros::Publisher turn_aux_rpt_pub
static const int64_t CAN_ID
ros::Publisher steering_pid_rpt_1_pub
ros::Publisher headlight_rpt_pub
std::unordered_map< long long, std::shared_ptr< LockedData > > rx_list
static const int64_t CAN_ID
ros::Publisher brake_aux_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher enabled_pub
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static const int64_t CAN_ID
ros::Publisher detected_object_rpt_pub
static const int64_t CAN_ID
void callback_accel_cmd_sub(const pacmod_msgs::SystemCmdFloat::ConstPtr &msg)
ros::Publisher steering_pid_rpt_3_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher steering_pid_rpt_2_pub
void send_can(long id, const std::vector< unsigned char > &vec)
static const int64_t CAN_ID
ros::Publisher vehicle_speed_ms_pub
ros::Publisher date_time_rpt_pub
static const int64_t CAN_ID
ros::Publisher wheel_speed_rpt_pub
void callback_steer_cmd_sub(const pacmod_msgs::SteerSystemCmd::ConstPtr &msg)
static const int64_t CAN_ID
ros::Publisher parking_brake_rpt_pub
static const int64_t CAN_ID
ros::Publisher lat_lon_heading_rpt_pub
static const int64_t CAN_ID
ros::Publisher yaw_rate_rpt_pub
static const int64_t CAN_ID
bool getParam(const std::string &key, std::string &s) const
void callback_horn_set_cmd(const pacmod_msgs::SystemCmdBool::ConstPtr &msg)
ros::Publisher horn_rpt_pub
ros::Publisher vehicle_dynamics_rpt_pub
ros::Publisher wiper_aux_rpt_pub
void callback_turn_signal_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
void callback_wiper_set_cmd(const pacmod_msgs::SystemCmdInt::ConstPtr &msg)
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
std::vector< uint8_t > data
static std::vector< uint8_t > unpackAndEncode(const int64_t &can_id, const pacmod_msgs::SystemCmdBool::ConstPtr &msg)
ros::Publisher brake_rpt_detail_2_pub
ros::Publisher brake_rpt_detail_3_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher global_rpt_pub
ros::Publisher vehicle_speed_pub
static const int64_t CAN_ID
ros::Publisher steer_aux_rpt_pub
ros::Publisher can_rx_pub
ros::Publisher accel_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher vin_rpt_pub
static const int64_t CAN_ID
ros::Publisher dash_controls_right_rpt_pub
ros::Publisher all_system_statuses_pub
static const int64_t CAN_ID