DbwNode.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018-2019, 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 _DBW_NODE_H_
36 #define _DBW_NODE_H_
37 
38 #include <ros/ros.h>
39 
40 // ROS messages
41 #include <can_msgs/Frame.h>
43 #include <dbw_fca_msgs/BrakeCmd.h>
44 #include <dbw_fca_msgs/BrakeReport.h>
45 #include <dbw_fca_msgs/ThrottleCmd.h>
46 #include <dbw_fca_msgs/ThrottleReport.h>
47 #include <dbw_fca_msgs/SteeringCmd.h>
48 #include <dbw_fca_msgs/SteeringReport.h>
49 #include <dbw_fca_msgs/GearCmd.h>
50 #include <dbw_fca_msgs/GearReport.h>
51 #include <dbw_fca_msgs/MiscCmd.h>
52 #include <dbw_fca_msgs/Misc1Report.h>
53 #include <dbw_fca_msgs/Misc2Report.h>
54 #include <dbw_fca_msgs/WheelPositionReport.h>
55 #include <dbw_fca_msgs/WheelSpeedReport.h>
56 #include <dbw_fca_msgs/FuelLevelReport.h>
57 #include <dbw_fca_msgs/TirePressureReport.h>
58 #include <dbw_fca_msgs/BrakeInfoReport.h>
59 #include <dbw_fca_msgs/ThrottleInfoReport.h>
60 #include <sensor_msgs/Imu.h>
61 #include <sensor_msgs/NavSatFix.h>
62 #include <sensor_msgs/TimeReference.h>
63 #include <sensor_msgs/JointState.h>
64 #include <geometry_msgs/TwistStamped.h>
65 #include <std_msgs/Empty.h>
66 #include <std_msgs/Bool.h>
67 #include <std_msgs/String.h>
68 
69 // Platform and module version map
71 
72 namespace dbw_fca_can
73 {
74 
75 class DbwNode
76 {
77 public:
79  ~DbwNode();
80 
81 private:
82  void timerCallback(const ros::TimerEvent& event);
83  void recvEnable(const std_msgs::Empty::ConstPtr& msg);
84  void recvDisable(const std_msgs::Empty::ConstPtr& msg);
85  void recvCAN(const can_msgs::Frame::ConstPtr& msg);
86  void recvBrakeCmd(const dbw_fca_msgs::BrakeCmd::ConstPtr& msg);
87  void recvThrottleCmd(const dbw_fca_msgs::ThrottleCmd::ConstPtr& msg);
88  void recvSteeringCmd(const dbw_fca_msgs::SteeringCmd::ConstPtr& msg);
89  void recvGearCmd(const dbw_fca_msgs::GearCmd::ConstPtr& msg);
90  void recvTurnSignalCmd(const dbw_fca_msgs::MiscCmd::ConstPtr& msg); // Backwards compatiblity
91  void recvMiscCmd(const dbw_fca_msgs::MiscCmd::ConstPtr& msg);
92  void recvCanImu(const std::vector<can_msgs::Frame::ConstPtr> &msgs);
93  void recvCanGps(const std::vector<can_msgs::Frame::ConstPtr> &msgs);
94 
97  bool enable_;
116  inline bool fault() { return fault_brakes_ || fault_throttle_ || fault_steering_ || fault_steering_cal_ || fault_watchdog_; }
117  inline bool override() { return override_brake_ || override_throttle_ || override_steering_ || override_gear_; }
118  inline bool clear() { return enable_ && override(); }
119  inline bool enabled() { return enable_ && !fault() && !override(); }
120  bool publishDbwEnabled();
121  void enableSystem();
122  void disableSystem();
123  void buttonCancel();
124  void overrideBrake(bool override, bool timeout);
125  void overrideThrottle(bool override, bool timeout);
126  void overrideSteering(bool override, bool timeout);
127  void overrideGear(bool override);
128  void timeoutBrake(bool timeout, bool enabled);
129  void timeoutThrottle(bool timeout, bool enabled);
130  void timeoutSteering(bool timeout, bool enabled);
131  void faultBrakes(bool fault);
132  void faultThrottle(bool fault);
133  void faultSteering(bool fault);
134  void faultSteeringCal(bool fault);
135  void faultWatchdog(bool fault, uint8_t src, bool braking);
136  void faultWatchdog(bool fault, uint8_t src = 0);
137 
138  enum {
139  JOINT_FL = 0, // Front left wheel
140  JOINT_FR, // Front right wheel
141  JOINT_RL, // Rear left wheel
142  JOINT_RR, // Rear right wheel
143  JOINT_SL, // Steering left
144  JOINT_SR, // Steering right
145  JOINT_COUNT, // Number of joints
146  };
147  sensor_msgs::JointState joint_state_;
148  void publishJointStates(const ros::Time &stamp, const dbw_fca_msgs::SteeringReport *steering);
149 
150  // The signum function: https://stackoverflow.com/questions/1903954/
151  template <typename T> static int sgn(T val) {
152  return ((T)0 < val) - (val < (T)0);
153  }
154 
155  // Sign of the wheel velocities, to be multiplied with vehicle speed
156  float speedSign() const {
157  return sgn(joint_state_.velocity[JOINT_FL]) + sgn(joint_state_.velocity[JOINT_FR]) +
158  sgn(joint_state_.velocity[JOINT_RL]) + sgn(joint_state_.velocity[JOINT_RR]) < 0 ? -1.0 : 1.0;
159  }
160 
161  // Licensing
162  std::string vin_;
163  std::string ldate_; // license date
164  std::map<uint8_t, std::string> bdate_;
165 
166  // Firmware Versions
168 
169  // Frame ID
170  std::string frame_id_;
171 
172  // Command warnings
174 
175  // Buttons (enable/disable)
176  bool buttons_;
177 
178  // Pedal LUTs (local/embedded)
180 
181  // Ackermann steering
183  double acker_track_;
186 
187  // Joint states (enable/disable)
189 
190  // Subscribed topics
200 
201  // Published topics
223 
224  // Time Synchronization
227 };
228 
229 } // namespace dbw_fca_can
230 
231 #endif // _DBW_NODE_H_
232 
double steering_ratio_
Definition: DbwNode.h:184
bool fault_watchdog_warned_
Definition: DbwNode.h:108
void recvCAN(const can_msgs::Frame::ConstPtr &msg)
Definition: DbwNode.cpp:205
ros::Publisher pub_wheel_speeds_
Definition: DbwNode.h:209
ros::Publisher pub_gps_fix_
Definition: DbwNode.h:216
void overrideThrottle(bool override, bool timeout)
Definition: DbwNode.cpp:1184
ros::Subscriber sub_turn_signal_
Definition: DbwNode.h:198
ros::Publisher pub_misc_1_
Definition: DbwNode.h:207
void faultWatchdog(bool fault, uint8_t src, bool braking)
Definition: DbwNode.cpp:1329
ros::Publisher pub_imu_
Definition: DbwNode.h:215
void recvGearCmd(const dbw_fca_msgs::GearCmd::ConstPtr &msg)
Definition: DbwNode.cpp:1007
double acker_wheelbase_
Definition: DbwNode.h:182
void timeoutThrottle(bool timeout, bool enabled)
Definition: DbwNode.cpp:1247
static int sgn(T val)
Definition: DbwNode.h:151
ros::Publisher pub_gps_time_
Definition: DbwNode.h:217
void overrideGear(bool override)
Definition: DbwNode.cpp:1222
ros::Subscriber sub_steering_
Definition: DbwNode.h:196
ros::Subscriber sub_throttle_
Definition: DbwNode.h:195
bool enable_joint_states_
Definition: DbwNode.h:188
void recvThrottleCmd(const dbw_fca_msgs::ThrottleCmd::ConstPtr &msg)
Definition: DbwNode.cpp:919
void recvCanImu(const std::vector< can_msgs::Frame::ConstPtr > &msgs)
Definition: DbwNode.cpp:749
void faultSteering(bool fault)
Definition: DbwNode.cpp:1297
ros::Subscriber sub_brake_
Definition: DbwNode.h:194
ros::Publisher pub_wheel_positions_
Definition: DbwNode.h:210
ros::Publisher pub_gps_fix_dr
Definition: DbwNode.h:218
void recvBrakeCmd(const dbw_fca_msgs::BrakeCmd::ConstPtr &msg)
Definition: DbwNode.cpp:844
std::string vin_
Definition: DbwNode.h:162
void faultSteeringCal(bool fault)
Definition: DbwNode.cpp:1313
void faultThrottle(bool fault)
Definition: DbwNode.cpp:1281
ros::Publisher pub_brake_info_
Definition: DbwNode.h:213
void recvSteeringCmd(const dbw_fca_msgs::SteeringCmd::ConstPtr &msg)
Definition: DbwNode.cpp:963
std::string frame_id_
Definition: DbwNode.h:170
ros::Subscriber sub_enable_
Definition: DbwNode.h:191
void recvDisable(const std_msgs::Empty::ConstPtr &msg)
Definition: DbwNode.cpp:200
ros::Publisher pub_throttle_info_
Definition: DbwNode.h:214
bool override_throttle_
Definition: DbwNode.h:99
ros::Publisher pub_brake_
Definition: DbwNode.h:203
std::map< uint8_t, std::string > bdate_
Definition: DbwNode.h:164
ros::Subscriber sub_can_
Definition: DbwNode.h:193
sensor_msgs::JointState joint_state_
Definition: DbwNode.h:147
bool fault_watchdog_using_brakes_
Definition: DbwNode.h:107
ros::Publisher pub_can_
Definition: DbwNode.h:202
ros::Publisher pub_joint_states_
Definition: DbwNode.h:219
void timerCallback(const ros::TimerEvent &event)
Definition: DbwNode.cpp:1077
PlatformMap firmware_
Definition: DbwNode.h:167
bool fault_steering_cal_
Definition: DbwNode.h:105
dataspeed_can_msg_filters::ApproximateTime sync_gps_
Definition: DbwNode.h:226
ros::Publisher pub_sys_enable_
Definition: DbwNode.h:222
void recvEnable(const std_msgs::Empty::ConstPtr &msg)
Definition: DbwNode.cpp:195
ros::Publisher pub_throttle_
Definition: DbwNode.h:204
void timeoutBrake(bool timeout, bool enabled)
Definition: DbwNode.cpp:1238
void overrideBrake(bool override, bool timeout)
Definition: DbwNode.cpp:1165
void overrideSteering(bool override, bool timeout)
Definition: DbwNode.cpp:1203
ros::Subscriber sub_gear_
Definition: DbwNode.h:197
dataspeed_can_msg_filters::ApproximateTime sync_imu_
Definition: DbwNode.h:225
void recvCanGps(const std::vector< can_msgs::Frame::ConstPtr > &msgs)
Definition: DbwNode.cpp:785
float speedSign() const
Definition: DbwNode.h:156
void faultBrakes(bool fault)
Definition: DbwNode.cpp:1265
ros::Publisher pub_misc_2_
Definition: DbwNode.h:208
ros::Publisher pub_gear_
Definition: DbwNode.h:206
ros::Subscriber sub_disable_
Definition: DbwNode.h:192
DbwNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh)
Definition: DbwNode.cpp:79
ros::Subscriber sub_misc_
Definition: DbwNode.h:199
void recvTurnSignalCmd(const dbw_fca_msgs::MiscCmd::ConstPtr &msg)
Definition: DbwNode.cpp:1024
ros::Publisher pub_tire_pressure_
Definition: DbwNode.h:211
std::string ldate_
Definition: DbwNode.h:163
ros::Publisher pub_fuel_level_
Definition: DbwNode.h:212
ros::Timer timer_
Definition: DbwNode.h:95
void publishJointStates(const ros::Time &stamp, const dbw_fca_msgs::SteeringReport *steering)
Definition: DbwNode.cpp:1410
void recvMiscCmd(const dbw_fca_msgs::MiscCmd::ConstPtr &msg)
Definition: DbwNode.cpp:1029
void timeoutSteering(bool timeout, bool enabled)
Definition: DbwNode.cpp:1256
ros::Publisher pub_twist_
Definition: DbwNode.h:220
ros::Publisher pub_vin_
Definition: DbwNode.h:221
ros::Publisher pub_steering_
Definition: DbwNode.h:205
double wheel_radius_
Definition: DbwNode.h:185


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Wed May 12 2021 02:14:05