PdsNode.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017-2018, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _PDS_NODE_H_
36 #define _PDS_NODE_H_
37 
38 #include <ros/ros.h>
39 
40 // ROS messages
41 #include <can_msgs/Frame.h>
43 #include <dataspeed_pds_msgs/Mode.h>
44 #include <dataspeed_pds_msgs/Relay.h>
45 #include <dataspeed_pds_msgs/Script.h>
46 #include <dataspeed_pds_msgs/Status.h>
47 
48 // Sync messages from multiple units
52 
53 namespace dataspeed_pds_can
54 {
55 
56 typedef enum {
57  MASTER = 0,
58  SLAVE1 = 1,
59  SLAVE2 = 2,
60  SLAVE3 = 3,
61 } UnitId;
62 
63 const ros::Duration TIMEOUT(0.5);
64 
65 class PdsNode
66 {
67 public:
68  PdsNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh);
69  ~PdsNode();
70 
71 private:
72  // ROS message callbacks
73  void recvCAN(const can_msgs::Frame::ConstPtr& msg);
74  void recvRelay(const dataspeed_pds_msgs::Relay::ConstPtr &msg);
75  void recvMode(const dataspeed_pds_msgs::Mode::ConstPtr &msg);
76  void recvScript(const dataspeed_pds_msgs::Script::ConstPtr &msg);
77 
78  // CAN message callbacks (synchronized)
79  void recvSync(const std::vector<can_msgs::Frame::ConstPtr> &msgs, UnitId id);
80 
81  // Inline conversion functions
82  float bytesToVoltage(uint16_t input) { return input * (float)0.01; }
83  float bytesToAmperes(int16_t input) { return input * (float)0.001; }
84  float bytesToCelsius(int8_t input) { return input * (float)0.5 + (float)44.0; }
85 
86  // Subscribed topics
91 
92  // Published topics
95 
96  // Detect presence of multiple units
100 
101  // Time synchronization of multiple CAN messages
106 
107  // Time synchronization of multiple units
108  typedef dataspeed_pds_msgs::Status SyncMsg;
109  typedef dataspeed_pds_msgs::Status::ConstPtr SyncPtr;
120  void recvSyncSlave1(const SyncPtr& master, const SyncPtr& slave1);
121  void recvSyncSlave2(const SyncPtr& master, const SyncPtr& slave1, const SyncPtr& slave2);
122  void recvSyncSlave3(const SyncPtr& master, const SyncPtr& slave1, const SyncPtr& slave2, const SyncPtr& slave3);
123 };
124 
125 } // namespace dataspeed_pds_can
126 
127 #endif // _PDS_NODE_H_
128 
dataspeed_pds_msgs::Status SyncMsg
Definition: PdsNode.h:108
void recvSync(const std::vector< can_msgs::Frame::ConstPtr > &msgs, UnitId id)
Definition: PdsNode.cpp:173
message_filters::Synchronizer< SyncPolicy3 > * sync_ros_slave3_
Definition: PdsNode.h:115
void recvMode(const dataspeed_pds_msgs::Mode::ConstPtr &msg)
Definition: PdsNode.cpp:152
message_filters::Synchronizer< SyncPolicy2 > * sync_ros_slave2_
Definition: PdsNode.h:114
float bytesToVoltage(uint16_t input)
Definition: PdsNode.h:82
dataspeed_pds_msgs::Status::ConstPtr SyncPtr
Definition: PdsNode.h:109
message_filters::PassThrough< SyncMsg > sync_msg_master_
Definition: PdsNode.h:116
message_filters::PassThrough< SyncMsg > sync_msg_slave1_
Definition: PdsNode.h:117
message_filters::PassThrough< SyncMsg > sync_msg_slave3_
Definition: PdsNode.h:119
message_filters::PassThrough< SyncMsg > sync_msg_slave2_
Definition: PdsNode.h:118
dataspeed_can_msg_filters::ApproximateTime sync_can_slave1_
Definition: PdsNode.h:103
ros::Publisher pub_can_
Definition: PdsNode.h:94
void recvSyncSlave3(const SyncPtr &master, const SyncPtr &slave1, const SyncPtr &slave2, const SyncPtr &slave3)
Definition: PdsNode.cpp:277
ros::Subscriber sub_can_
Definition: PdsNode.h:90
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg > SyncPolicy1
Definition: PdsNode.h:110
ros::Subscriber sub_relay_
Definition: PdsNode.h:87
dataspeed_can_msg_filters::ApproximateTime sync_can_slave2_
Definition: PdsNode.h:104
void recvRelay(const dataspeed_pds_msgs::Relay::ConstPtr &msg)
Definition: PdsNode.cpp:141
void recvCAN(const can_msgs::Frame::ConstPtr &msg)
Definition: PdsNode.cpp:91
void recvScript(const dataspeed_pds_msgs::Script::ConstPtr &msg)
Definition: PdsNode.cpp:162
dataspeed_can_msg_filters::ApproximateTime sync_can_master_
Definition: PdsNode.h:102
const ros::Duration TIMEOUT(0.5)
PdsNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh)
Definition: PdsNode.cpp:41
float bytesToAmperes(int16_t input)
Definition: PdsNode.h:83
float bytesToCelsius(int8_t input)
Definition: PdsNode.h:84
ros::Subscriber sub_script_
Definition: PdsNode.h:89
dataspeed_can_msg_filters::ApproximateTime sync_can_slave3_
Definition: PdsNode.h:105
ros::Publisher pub_status_
Definition: PdsNode.h:93
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg, SyncMsg, SyncMsg > SyncPolicy3
Definition: PdsNode.h:112
message_filters::Synchronizer< SyncPolicy1 > * sync_ros_slave1_
Definition: PdsNode.h:113
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg, SyncMsg > SyncPolicy2
Definition: PdsNode.h:111
void recvSyncSlave2(const SyncPtr &master, const SyncPtr &slave1, const SyncPtr &slave2)
Definition: PdsNode.cpp:266
void recvSyncSlave1(const SyncPtr &master, const SyncPtr &slave1)
Definition: PdsNode.cpp:257
ros::Subscriber sub_mode_
Definition: PdsNode.h:88


dataspeed_pds_can
Author(s): Kevin Hallenbeck , Eric Myllyoja
autogenerated on Sat Jul 11 2020 03:09:52