PdsNode.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017-2018, Dataspeed Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Dataspeed Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #ifndef _PDS_NODE_H_
00036 #define _PDS_NODE_H_
00037 
00038 #include <ros/ros.h>
00039 
00040 // ROS messages
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 // Sync messages from multiple units
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   // ROS message callbacks
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   // CAN message callbacks (synchronized)
00079   void recvSync(const std::vector<can_msgs::Frame::ConstPtr> &msgs, UnitId id);
00080 
00081   // Inline conversion functions
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   // Subscribed topics
00087   ros::Subscriber sub_relay_;
00088   ros::Subscriber sub_mode_;
00089   ros::Subscriber sub_script_;
00090   ros::Subscriber sub_can_;
00091 
00092   // Published topics
00093   ros::Publisher pub_status_;
00094   ros::Publisher pub_can_;
00095 
00096   // Detect presence of multiple units
00097   ros::Time stamp_slave1_;
00098   ros::Time stamp_slave2_;
00099   ros::Time stamp_slave3_;
00100 
00101   // Time synchronization of multiple CAN messages
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   // Time synchronization of multiple units
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 } // namespace dataspeed_pds_can
00126 
00127 #endif // _PDS_NODE_H_
00128 


dataspeed_pds_can
Author(s): Kevin Hallenbeck , Eric Myllyoja
autogenerated on Thu Apr 4 2019 02:42:49