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


dbw_mkz_can
Author(s): Kevin Hallenbeck
autogenerated on Fri May 14 2021 02:47:08