PdsNode.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017-2020, 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_can::PdsNode::sync_ros_slave2_
message_filters::Synchronizer< SyncPolicy2 > * sync_ros_slave2_
Definition: PdsNode.h:146
dataspeed_pds_can::PdsNode::recvCAN
void recvCAN(const can_msgs::Frame::ConstPtr &msg)
Definition: PdsNode.cpp:123
dataspeed_pds_can::PdsNode::sub_can_
ros::Subscriber sub_can_
Definition: PdsNode.h:122
dataspeed_pds_can::PdsNode::recvMode
void recvMode(const dataspeed_pds_msgs::Mode::ConstPtr &msg)
Definition: PdsNode.cpp:184
dataspeed_pds_can::PdsNode::sub_script_
ros::Subscriber sub_script_
Definition: PdsNode.h:121
ros::Publisher
dataspeed_pds_can::PdsNode::SyncPtr
dataspeed_pds_msgs::Status::ConstPtr SyncPtr
Definition: PdsNode.h:141
dataspeed_pds_can::PdsNode::stamp_slave2_
ros::Time stamp_slave2_
Definition: PdsNode.h:130
message_filters::Synchronizer
pass_through.h
dataspeed_pds_can::PdsNode::sync_ros_slave1_
message_filters::Synchronizer< SyncPolicy1 > * sync_ros_slave1_
Definition: PdsNode.h:145
dataspeed_pds_can::SLAVE3
@ SLAVE3
Definition: PdsNode.h:124
dataspeed_pds_can::PdsNode::stamp_slave3_
ros::Time stamp_slave3_
Definition: PdsNode.h:131
ros.h
dataspeed_pds_can::SLAVE1
@ SLAVE1
Definition: PdsNode.h:122
dataspeed_pds_can::PdsNode::recvScript
void recvScript(const dataspeed_pds_msgs::Script::ConstPtr &msg)
Definition: PdsNode.cpp:194
dataspeed_pds_can::PdsNode::sync_can_slave3_
dataspeed_can_msg_filters::ApproximateTime sync_can_slave3_
Definition: PdsNode.h:137
dataspeed_pds_can::TIMEOUT
const ros::Duration TIMEOUT(0.5)
dataspeed_pds_can::PdsNode::recvSyncSlave1
void recvSyncSlave1(const SyncPtr &master, const SyncPtr &slave1)
Definition: PdsNode.cpp:305
dataspeed_pds_can::PdsNode::sync_msg_slave2_
message_filters::PassThrough< SyncMsg > sync_msg_slave2_
Definition: PdsNode.h:150
dataspeed_pds_can::PdsNode::recvSync
void recvSync(const std::vector< can_msgs::Frame::ConstPtr > &msgs, UnitId id)
Definition: PdsNode.cpp:205
message_filters::sync_policies::ApproximateTime
dataspeed_pds_can::PdsNode::sync_msg_slave1_
message_filters::PassThrough< SyncMsg > sync_msg_slave1_
Definition: PdsNode.h:149
dataspeed_pds_can::PdsNode::sync_msg_master_
message_filters::PassThrough< SyncMsg > sync_msg_master_
Definition: PdsNode.h:148
dataspeed_pds_can::PdsNode::~PdsNode
~PdsNode()
Definition: PdsNode.cpp:107
dataspeed_pds_can::PdsNode::SyncPolicy1
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg > SyncPolicy1
Definition: PdsNode.h:142
dataspeed_pds_can
Definition: dispatch.h:39
dataspeed_pds_can::PdsNode::sub_mode_
ros::Subscriber sub_mode_
Definition: PdsNode.h:120
dataspeed_pds_can::PdsNode::stamp_slave1_
ros::Time stamp_slave1_
Definition: PdsNode.h:129
dataspeed_pds_can::PdsNode::recvRelay
void recvRelay(const dataspeed_pds_msgs::Relay::ConstPtr &msg)
Definition: PdsNode.cpp:173
dataspeed_pds_can::PdsNode::sync_can_slave2_
dataspeed_can_msg_filters::ApproximateTime sync_can_slave2_
Definition: PdsNode.h:136
dataspeed_pds_can::PdsNode::sync_can_slave1_
dataspeed_can_msg_filters::ApproximateTime sync_can_slave1_
Definition: PdsNode.h:135
dataspeed_pds_can::PdsNode::pub_can_
ros::Publisher pub_can_
Definition: PdsNode.h:126
ApproximateTime.h
dataspeed_pds_can::PdsNode::pub_status_
ros::Publisher pub_status_
Definition: PdsNode.h:125
ros::Time
message_filters::PassThrough< SyncMsg >
dataspeed_pds_can::PdsNode::sync_ros_slave3_
message_filters::Synchronizer< SyncPolicy3 > * sync_ros_slave3_
Definition: PdsNode.h:147
dataspeed_pds_can::PdsNode::bytesToVoltage
float bytesToVoltage(uint16_t input)
Definition: PdsNode.h:114
dataspeed_pds_can::PdsNode::sync_msg_slave3_
message_filters::PassThrough< SyncMsg > sync_msg_slave3_
Definition: PdsNode.h:151
synchronizer.h
dataspeed_pds_can::PdsNode::SyncPolicy3
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg, SyncMsg, SyncMsg > SyncPolicy3
Definition: PdsNode.h:144
dataspeed_pds_can::SLAVE2
@ SLAVE2
Definition: PdsNode.h:123
approximate_time.h
dataspeed_pds_can::MASTER
@ MASTER
Definition: PdsNode.h:121
dataspeed_pds_can::PdsNode::recvSyncSlave2
void recvSyncSlave2(const SyncPtr &master, const SyncPtr &slave1, const SyncPtr &slave2)
Definition: PdsNode.cpp:314
dataspeed_pds_can::PdsNode::bytesToAmperes
float bytesToAmperes(int16_t input)
Definition: PdsNode.h:115
dataspeed_pds_can::UnitId
UnitId
Definition: PdsNode.h:88
dataspeed_pds_can::PdsNode::recvSyncSlave3
void recvSyncSlave3(const SyncPtr &master, const SyncPtr &slave1, const SyncPtr &slave2, const SyncPtr &slave3)
Definition: PdsNode.cpp:325
dataspeed_pds_can::PdsNode::sub_relay_
ros::Subscriber sub_relay_
Definition: PdsNode.h:119
dataspeed_pds_can::PdsNode::PdsNode
PdsNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh)
Definition: PdsNode.cpp:73
ros::Duration
dataspeed_pds_can::PdsNode::bytesToCelsius
float bytesToCelsius(int8_t input)
Definition: PdsNode.h:116
dataspeed_pds_can::PdsNode::sync_can_master_
dataspeed_can_msg_filters::ApproximateTime sync_can_master_
Definition: PdsNode.h:134
dataspeed_can_msg_filters::ApproximateTime
dataspeed_pds_can::PdsNode::SyncPolicy2
message_filters::sync_policies::ApproximateTime< SyncMsg, SyncMsg, SyncMsg > SyncPolicy2
Definition: PdsNode.h:143
ros::NodeHandle
ros::Subscriber
dataspeed_pds_can::PdsNode::SyncMsg
dataspeed_pds_msgs::Status SyncMsg
Definition: PdsNode.h:140


dataspeed_pds_can
Author(s): Kevin Hallenbeck , Eric Myllyoja , Michael Lohrer
autogenerated on Wed Mar 2 2022 00:11:44