29 #include <unordered_map> 34 #include <std_msgs/Int16.h> 35 #include <std_msgs/Bool.h> 36 #include <std_msgs/Float64.h> 37 #include <can_msgs/Frame.h> 88 std::unordered_map<int64_t, std::shared_ptr<LockedData>>
rx_list;
121 auto rx_it =
rx_list.find(can_id);
126 rx_it->second->setIsValid(
true);
130 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
138 auto rx_it =
rx_list.find(can_id);
143 rx_it->second->setIsValid(
true);
147 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
155 auto rx_it =
rx_list.find(can_id);
160 rx_it->second->setIsValid(
true);
164 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
172 auto rx_it =
rx_list.find(can_id);
177 rx_it->second->setIsValid(
true);
181 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
189 auto rx_it =
rx_list.find(can_id);
194 rx_it->second->setIsValid(
true);
198 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
206 auto rx_it =
rx_list.find(can_id);
211 rx_it->second->setIsValid(
true);
215 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
223 auto rx_it =
rx_list.find(can_id);
228 rx_it->second->setIsValid(
true);
232 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
240 auto rx_it =
rx_list.find(can_id);
245 rx_it->second->setIsValid(
true);
249 ROS_WARN(
"Received command message for ID 0x%lx for which we did not have an encoder.", can_id);
253 void send_can(int32_t
id,
const std::vector<unsigned char>& vec)
255 can_msgs::Frame frame;
257 frame.is_rtr =
false;
258 frame.is_extended =
false;
259 frame.is_error =
false;
261 std::copy(vec.begin(), vec.end(), frame.data.begin());
270 std::vector<unsigned char> data;
272 const std::chrono::milliseconds loop_pause = std::chrono::milliseconds(33);
273 const std::chrono::milliseconds inter_msg_pause = std::chrono::milliseconds(1);
274 bool keep_going =
true;
305 global_obj.
encode(local_enable,
true,
false);
310 std::this_thread::sleep_for(inter_msg_pause);
315 for (
const auto& element :
rx_list)
318 if (element.second->isValid())
320 send_can(element.first, element.second->getData());
321 std::this_thread::sleep_for(inter_msg_pause);
326 std::chrono::system_clock::time_point next_time = std::chrono::system_clock::now();
327 next_time += loop_pause;
328 std::this_thread::sleep_until(next_time);
337 void can_read(
const can_msgs::Frame::ConstPtr &msg)
339 std_msgs::Bool bool_pub_msg;
344 if (parser_class != NULL && pub !=
pub_tx_list.end())
346 parser_class->parse(const_cast<unsigned char *>(&msg->data[0]));
347 handler.
fillAndPublish(msg->id,
"pacmod", pub->second, parser_class);
349 bool local_enable =
false;
367 auto rx_it =
rx_list.find(cmd->second);
376 encoder.
encode(dc_parser->output);
377 rx_it->second->setData(encoder.data);
381 auto dc_parser = std::dynamic_pointer_cast<
ShiftRptMsg>(parser_class);
384 encoder.
encode(dc_parser->output);
385 rx_it->second->setData(encoder.data);
389 auto dc_parser = std::dynamic_pointer_cast<
AccelRptMsg>(parser_class);
392 encoder.
encode(dc_parser->output);
393 rx_it->second->setData(encoder.data);
397 auto dc_parser = std::dynamic_pointer_cast<
SteerRptMsg>(parser_class);
400 encoder.
encode(dc_parser->output, 2.0);
401 rx_it->second->setData(encoder.data);
405 auto dc_parser = std::dynamic_pointer_cast<
BrakeRptMsg>(parser_class);
408 encoder.
encode(dc_parser->output);
409 rx_it->second->setData(encoder.data);
413 auto dc_parser = std::dynamic_pointer_cast<
WiperRptMsg>(parser_class);
416 encoder.
encode(dc_parser->output);
417 rx_it->second->setData(encoder.data);
421 auto dc_parser = std::dynamic_pointer_cast<
HornRptMsg>(parser_class);
424 encoder.
encode(dc_parser->output);
425 rx_it->second->setData(encoder.data);
428 rx_it->second->setIsValid(
true);
435 auto dc_parser = std::dynamic_pointer_cast<
GlobalRptMsg>(parser_class);
437 bool_pub_msg.data = (dc_parser->enabled);
438 enable_pub.
publish(bool_pub_msg);
440 if (dc_parser->override_active)
450 std_msgs::Float64 veh_spd_ms_msg;
451 veh_spd_ms_msg.data = (dc_parser->vehicle_speed) * 0.44704;
452 vehicle_speed_ms_pub.
publish(veh_spd_ms_msg);
457 int main(
int argc,
char *argv[])
492 ROS_WARN(
"PACMod - An invalid vehicle type was entered. Assuming POLARIS_GEM.");
497 can_rx_pub = n.
advertise<can_msgs::Frame>(
"can_rx", 20);
498 global_rpt_pub = n.
advertise<pacmod_msgs::GlobalRpt>(
"parsed_tx/global_rpt", 20);
499 vin_rpt_pub = n.
advertise<pacmod_msgs::VinRpt>(
"parsed_tx/vin_rpt", 5);
500 turn_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/turn_rpt", 20);
501 shift_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/shift_rpt", 20);
502 accel_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/accel_rpt", 20);
503 steer_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/steer_rpt", 20);
504 brake_rpt_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/brake_rpt", 20);
505 vehicle_speed_pub = n.
advertise<pacmod_msgs::VehicleSpeedRpt>(
"parsed_tx/vehicle_speed_rpt", 20);
506 vehicle_speed_ms_pub = n.
advertise<std_msgs::Float64>(
"as_tx/vehicle_speed", 20);
507 enable_pub = n.
advertise<std_msgs::Bool>(
"as_tx/enable", 20,
true);
509 std::string frame_id =
"pacmod";
531 std::shared_ptr<LockedData> global_data(
new LockedData);
532 std::shared_ptr<LockedData> turn_data(
new LockedData);
533 std::shared_ptr<LockedData> shift_data(
new LockedData);
534 std::shared_ptr<LockedData> accel_data(
new LockedData);
535 std::shared_ptr<LockedData> steer_data(
new LockedData);
536 std::shared_ptr<LockedData> brake_data(
new LockedData);
549 brake_rpt_detail_1_pub = n.
advertise<pacmod_msgs::MotorRpt1>(
"parsed_tx/brake_rpt_detail_1", 20);
550 brake_rpt_detail_2_pub = n.
advertise<pacmod_msgs::MotorRpt2>(
"parsed_tx/brake_rpt_detail_2", 20);
551 brake_rpt_detail_3_pub = n.
advertise<pacmod_msgs::MotorRpt3>(
"parsed_tx/brake_rpt_detail_3", 20);
552 steering_rpt_detail_1_pub = n.
advertise<pacmod_msgs::MotorRpt1>(
"parsed_tx/steer_rpt_detail_1", 20);
553 steering_rpt_detail_2_pub = n.
advertise<pacmod_msgs::MotorRpt2>(
"parsed_tx/steer_rpt_detail_2", 20);
554 steering_rpt_detail_3_pub = n.
advertise<pacmod_msgs::MotorRpt3>(
"parsed_tx/steer_rpt_detail_3", 20);
566 wiper_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/wiper_rpt", 20);
574 std::shared_ptr<LockedData> wiper_data(
new LockedData);
580 horn_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/horn_rpt", 20);
581 steer_rpt_2_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/steer_rpt_2", 20);
582 steer_rpt_3_pub = n.
advertise<pacmod_msgs::SystemRptFloat>(
"parsed_tx/steer_rpt_3", 20);
583 wheel_speed_rpt_pub = n.
advertise<pacmod_msgs::WheelSpeedRpt>(
"parsed_tx/wheel_speed_rpt", 20);
584 steering_pid_rpt_1_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt1>(
"parsed_tx/steer_pid_rpt_1", 20);
585 steering_pid_rpt_2_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt2>(
"parsed_tx/steer_pid_rpt_2", 20);
586 steering_pid_rpt_3_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt3>(
"parsed_tx/steer_pid_rpt_3", 20);
587 steering_pid_rpt_4_pub = n.
advertise<pacmod_msgs::SteeringPIDRpt4>(
"parsed_tx/steer_pid_rpt_4", 20);
588 yaw_rate_rpt_pub = n.
advertise<pacmod_msgs::YawRateRpt>(
"parsed_tx/yaw_rate_rpt", 20);
589 lat_lon_heading_rpt_pub = n.
advertise<pacmod_msgs::LatLonHeadingRpt>(
"parsed_tx/lat_lon_heading_rpt", 20);
590 date_time_rpt_pub = n.
advertise<pacmod_msgs::DateTimeRpt>(
"parsed_tx/date_time_rpt", 20);
613 std::shared_ptr<LockedData> headlight_data(
new LockedData);
614 std::shared_ptr<LockedData> horn_data(
new LockedData);
622 headlight_rpt_pub = n.
advertise<pacmod_msgs::SystemRptInt>(
"parsed_tx/headlight_rpt", 20);
623 parking_brake_status_rpt_pub =
624 n.
advertise<pacmod_msgs::ParkingBrakeStatusRpt>(
"parsed_tx/parking_brake_status_rpt", 20);
663 can_write_thread.join();
void set_enable(bool val)
ros::Publisher steering_rpt_detail_2_pub
ros::Publisher accel_rpt_pub
static const int64_t CAN_ID
ros::Publisher headlight_rpt_pub
void callback_pacmod_enable(const std_msgs::Bool::ConstPtr &msg)
std::unordered_map< int64_t, std::shared_ptr< LockedData > > rx_list
ros::Publisher vin_rpt_pub
void can_read(const can_msgs::Frame::ConstPtr &msg)
ros::Publisher yaw_rate_rpt_pub
static const int64_t CAN_ID
const double watchdog_timeout
void encode(uint8_t turn_signal_cmd)
ros::Publisher date_time_rpt_pub
static const int64_t CAN_ID
std::shared_ptr< ros::Subscriber > wiper_set_cmd_sub
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static const int64_t CAN_ID
void callback_turn_signal_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
void encode(double steer_pos, double steer_spd)
static const int64_t CAN_ID
std::unordered_map< int64_t, int64_t > rpt_cmd_list
ros::Publisher steer_rpt_pub
static const int64_t CAN_ID
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher vehicle_speed_ms_pub
double last_global_rpt_msg_received
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher steering_pid_rpt_2_pub
ros::Publisher turn_rpt_pub
static const int64_t CAN_ID
ros::Publisher can_rx_pub
void callback_wiper_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
ros::Publisher steer_rpt_3_pub
ros::Publisher steering_pid_rpt_3_pub
static const int64_t CAN_ID
void encode(double accel_cmd)
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher steering_rpt_detail_1_pub
ros::Publisher steering_pid_rpt_1_pub
static std::shared_ptr< PacmodTxMsg > make_message(const int64_t &can_id)
static const int64_t CAN_ID
static const int64_t CAN_ID
std::vector< uint8_t > data
void encode(uint8_t horn_cmd)
ros::Publisher brake_rpt_detail_3_pub
int main(int argc, char *argv[])
ros::Publisher wiper_rpt_pub
ros::Publisher shift_rpt_pub
void publish(const boost::shared_ptr< M > &message) const
static std::vector< uint8_t > unpackAndEncode(const int64_t &can_id, const pacmod_msgs::PacmodCmd::ConstPtr &msg)
std::string veh_type_string
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher horn_rpt_pub
static const int64_t CAN_ID
ros::Publisher wheel_speed_rpt_pub
void encode(uint8_t shift_cmd)
static const int64_t CAN_ID
void callback_brake_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
bool getParam(const std::string &key, std::string &s) const
void callback_shift_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
static const int64_t CAN_ID
ros::Publisher steering_pid_rpt_4_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher steer_rpt_2_pub
std::chrono::milliseconds can_error_pause
ros::Publisher parking_brake_status_rpt_pub
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher brake_rpt_detail_1_pub
void encode(double brake_cmd)
void callback_horn_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
ros::Publisher enable_pub
static const int64_t CAN_ID
void encode(bool enable, bool clear_override, bool ignore_overide)
std::shared_ptr< ros::Subscriber > horn_set_cmd_sub
static const int64_t CAN_ID
PacmodTxRosMsgHandler handler
ros::Publisher brake_rpt_detail_2_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
ros::Publisher vehicle_speed_pub
static const int64_t CAN_ID
void encode(uint8_t wiper_cmd)
ros::Publisher global_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
static const int64_t CAN_ID
void fillAndPublish(const int64_t &can_id, std::string frame_id, const ros::Publisher &pub, const std::shared_ptr< PacmodTxMsg > &parser_class)
ros::Publisher lat_lon_heading_rpt_pub
ros::Publisher steering_rpt_detail_3_pub
void send_can(int32_t id, const std::vector< unsigned char > &vec)
ros::Publisher brake_rpt_pub
static const int64_t CAN_ID
static const int64_t CAN_ID
std::mutex keep_going_mut
static const int64_t CAN_ID
static const int64_t CAN_ID
std::unordered_map< int64_t, ros::Publisher > pub_tx_list
static const int64_t CAN_ID
void callback_steering_set_cmd(const pacmod_msgs::PositionWithSpeed::ConstPtr &msg)
std::shared_ptr< ros::Subscriber > headlight_set_cmd_sub
void callback_headlight_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)
ROSCPP_DECL void waitForShutdown()
void callback_accelerator_set_cmd(const pacmod_msgs::PacmodCmd::ConstPtr &msg)