Go to the documentation of this file.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 #ifndef _PDS_NODE_H_
00036 #define _PDS_NODE_H_
00037
00038 #include <ros/ros.h>
00039
00040
00041 #include <can_msgs/Frame.h>
00042 #include <dataspeed_can_msg_filters/ApproximateTime.h>
00043 #include <dataspeed_pds_msgs/Mode.h>
00044 #include <dataspeed_pds_msgs/Relay.h>
00045 #include <dataspeed_pds_msgs/Script.h>
00046 #include <dataspeed_pds_msgs/Status.h>
00047
00048
00049 #include <message_filters/pass_through.h>
00050 #include <message_filters/synchronizer.h>
00051 #include <message_filters/sync_policies/approximate_time.h>
00052
00053 namespace dataspeed_pds_can
00054 {
00055
00056 typedef enum {
00057 MASTER = 0,
00058 SLAVE1 = 1,
00059 SLAVE2 = 2,
00060 SLAVE3 = 3,
00061 } UnitId;
00062
00063 const ros::Duration TIMEOUT(0.5);
00064
00065 class PdsNode
00066 {
00067 public:
00068 PdsNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh);
00069 ~PdsNode();
00070
00071 private:
00072
00073 void recvCAN(const can_msgs::Frame::ConstPtr& msg);
00074 void recvRelay(const dataspeed_pds_msgs::Relay::ConstPtr &msg);
00075 void recvMode(const dataspeed_pds_msgs::Mode::ConstPtr &msg);
00076 void recvScript(const dataspeed_pds_msgs::Script::ConstPtr &msg);
00077
00078
00079 void recvSync(const std::vector<can_msgs::Frame::ConstPtr> &msgs, UnitId id);
00080
00081
00082 float bytesToVoltage(uint16_t input) { return input * (float)0.01; }
00083 float bytesToAmperes(int16_t input) { return input * (float)0.001; }
00084 float bytesToCelsius(int8_t input) { return input * (float)0.5 + (float)44.0; }
00085
00086
00087 ros::Subscriber sub_relay_;
00088 ros::Subscriber sub_mode_;
00089 ros::Subscriber sub_script_;
00090 ros::Subscriber sub_can_;
00091
00092
00093 ros::Publisher pub_status_;
00094 ros::Publisher pub_can_;
00095
00096
00097 ros::Time stamp_slave1_;
00098 ros::Time stamp_slave2_;
00099 ros::Time stamp_slave3_;
00100
00101
00102 dataspeed_can_msg_filters::ApproximateTime sync_can_master_;
00103 dataspeed_can_msg_filters::ApproximateTime sync_can_slave1_;
00104 dataspeed_can_msg_filters::ApproximateTime sync_can_slave2_;
00105 dataspeed_can_msg_filters::ApproximateTime sync_can_slave3_;
00106
00107
00108 typedef dataspeed_pds_msgs::Status SyncMsg;
00109 typedef dataspeed_pds_msgs::Status::ConstPtr SyncPtr;
00110 typedef message_filters::sync_policies::ApproximateTime<SyncMsg, SyncMsg> SyncPolicy1;
00111 typedef message_filters::sync_policies::ApproximateTime<SyncMsg, SyncMsg, SyncMsg> SyncPolicy2;
00112 typedef message_filters::sync_policies::ApproximateTime<SyncMsg, SyncMsg, SyncMsg, SyncMsg> SyncPolicy3;
00113 message_filters::Synchronizer<SyncPolicy1> *sync_ros_slave1_;
00114 message_filters::Synchronizer<SyncPolicy2> *sync_ros_slave2_;
00115 message_filters::Synchronizer<SyncPolicy3> *sync_ros_slave3_;
00116 message_filters::PassThrough<SyncMsg> sync_msg_master_;
00117 message_filters::PassThrough<SyncMsg> sync_msg_slave1_;
00118 message_filters::PassThrough<SyncMsg> sync_msg_slave2_;
00119 message_filters::PassThrough<SyncMsg> sync_msg_slave3_;
00120 void recvSyncSlave1(const SyncPtr& master, const SyncPtr& slave1);
00121 void recvSyncSlave2(const SyncPtr& master, const SyncPtr& slave1, const SyncPtr& slave2);
00122 void recvSyncSlave3(const SyncPtr& master, const SyncPtr& slave1, const SyncPtr& slave2, const SyncPtr& slave3);
00123 };
00124
00125 }
00126
00127 #endif // _PDS_NODE_H_
00128