DbwNode.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018-2019 New Eagle
5  * Copyright (c) 2015-2018, Dataspeed Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Dataspeed Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #ifndef _DBW_NODE_H_
37 #define _DBW_NODE_H_
38 
39 #include <ros/ros.h>
40 
41 // ROS messages
42 #include <can_msgs/Frame.h>
43 #include <dbw_pacifica_msgs/BrakeCmd.h>
44 #include <dbw_pacifica_msgs/BrakeReport.h>
45 #include <dbw_pacifica_msgs/AcceleratorPedalCmd.h>
46 #include <dbw_pacifica_msgs/AcceleratorPedalReport.h>
47 #include <dbw_pacifica_msgs/SteeringCmd.h>
48 #include <dbw_pacifica_msgs/SteeringReport.h>
49 #include <dbw_pacifica_msgs/GearCmd.h>
50 #include <dbw_pacifica_msgs/GearReport.h>
51 #include <dbw_pacifica_msgs/MiscCmd.h>
52 #include <dbw_pacifica_msgs/MiscReport.h>
53 #include <dbw_pacifica_msgs/WheelPositionReport.h>
54 #include <dbw_pacifica_msgs/WheelSpeedReport.h>
55 #include <dbw_pacifica_msgs/TirePressureReport.h>
56 #include <dbw_pacifica_msgs/SurroundReport.h>
57 #include <dbw_pacifica_msgs/DriverInputReport.h>
58 #include <dbw_pacifica_msgs/LowVoltageSystemReport.h>
59 #include <dbw_pacifica_msgs/ActuatorControlMode.h>
60 #include <dbw_pacifica_msgs/Brake2Report.h>
61 #include <dbw_pacifica_msgs/Steering2Report.h>
62 #include <dbw_pacifica_msgs/GlobalEnableCmd.h>
63 #include <dbw_pacifica_msgs/FaultActionsReport.h>
64 #include <dbw_pacifica_msgs/HmiGlobalEnableReport.h>
65 
66 #include <sensor_msgs/Imu.h>
67 #include <sensor_msgs/JointState.h>
68 #include <geometry_msgs/TwistStamped.h>
69 #include <std_msgs/Empty.h>
70 #include <std_msgs/Bool.h>
71 #include <std_msgs/String.h>
72 
73 //#include <dbc/DbcUtilities.h>
74 #include <dbc/DbcMessage.h>
75 #include <dbc/DbcSignal.h>
76 #include <dbc/Dbc.h>
77 #include <dbc/DbcBuilder.h>
78 
79 #include <pdu_msgs/RelayCommand.h>
80 #include <pdu_msgs/RelayState.h>
81 
82 namespace dbw_pacifica_can
83 {
84 
85 class DbwNode
86 {
87 public:
88  DbwNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh);
89  ~DbwNode();
90 
91 private:
92  void timerCallback(const ros::TimerEvent& event);
93  void recvEnable(const std_msgs::Empty::ConstPtr& msg);
94  void recvDisable(const std_msgs::Empty::ConstPtr& msg);
95  void recvCAN(const can_msgs::Frame::ConstPtr& msg);
96  void recvCanImu(const std::vector<can_msgs::Frame::ConstPtr> &msgs);
97  void recvCanGps(const std::vector<can_msgs::Frame::ConstPtr> &msgs);
98  void recvBrakeCmd(const dbw_pacifica_msgs::BrakeCmd::ConstPtr& msg);
99  void recvAcceleratorPedalCmd(const dbw_pacifica_msgs::AcceleratorPedalCmd::ConstPtr& msg);
100  void recvSteeringCmd(const dbw_pacifica_msgs::SteeringCmd::ConstPtr& msg);
101  void recvGearCmd(const dbw_pacifica_msgs::GearCmd::ConstPtr& msg);
102  void recvMiscCmd(const dbw_pacifica_msgs::MiscCmd::ConstPtr& msg);
103  void recvGlobalEnableCmd(const dbw_pacifica_msgs::GlobalEnableCmd::ConstPtr& msg);
104 
107  bool enable_;
126  inline bool fault() { return fault_brakes_ || fault_accelerator_pedal_ || fault_steering_ || fault_steering_cal_ || fault_watchdog_; }
127  inline bool override() { return override_brake_ || override_accelerator_pedal_ || override_steering_ || override_gear_; }
128  inline bool clear() { return enable_ && override(); }
129  inline bool enabled() { return enable_ && !fault() && !override(); }
130  bool publishDbwEnabled();
131  void enableSystem();
132  void disableSystem();
133  void buttonCancel();
134  void overrideBrake(bool override);
135  void overrideAcceleratorPedal(bool override);
136  void overrideSteering(bool override);
137  void overrideGear(bool override);
138  void timeoutBrake(bool timeout, bool enabled);
139  void timeoutAcceleratorPedal(bool timeout, bool enabled);
140  void timeoutSteering(bool timeout, bool enabled);
141  void faultBrakes(bool fault);
142  void faultAcceleratorPedal(bool fault);
143  void faultSteering(bool fault);
144  void faultSteeringCal(bool fault);
145  void faultWatchdog(bool fault, uint8_t src, bool braking);
146  void faultWatchdog(bool fault, uint8_t src = 0);
147 
148  enum {
149  JOINT_FL = 0, // Front left wheel
150  JOINT_FR, // Front right wheel
151  JOINT_RL, // Rear left wheel
152  JOINT_RR, // Rear right wheel
153  JOINT_SL, // Steering left
154  JOINT_SR, // Steering right
155  JOINT_COUNT, // Number of joints
156  };
157  sensor_msgs::JointState joint_state_;
158  void publishJointStates(const ros::Time &stamp, const dbw_pacifica_msgs::WheelSpeedReport *wheels, const dbw_pacifica_msgs::SteeringReport *steering);
159  // Licensing
160  std::string vin_;
161 
162  // Frame ID
163  std::string frame_id_;
164 
165  // Buttons (enable/disable)
166  bool buttons_;
167 
168  // Ackermann steering
170  double acker_track_;
172 
173  // Subscribed topics
183 
184  // Published topics
202 
207 
209  std::string dbcFile_;
210 
211  // Test stuff
213  uint32_t count_;
214 };
215 
216 } // dbw_pacifica_can
217 
218 #endif // _DBW_NODE_H_
219 
void recvGearCmd(const dbw_pacifica_msgs::GearCmd::ConstPtr &msg)
Definition: DbwNode.cpp:824
ros::Subscriber sub_can_
Definition: DbwNode.h:176
void publishJointStates(const ros::Time &stamp, const dbw_pacifica_msgs::WheelSpeedReport *wheels, const dbw_pacifica_msgs::SteeringReport *steering)
Definition: DbwNode.cpp:1273
ros::Publisher pub_brake_2_report_
Definition: DbwNode.h:203
void recvMiscCmd(const dbw_pacifica_msgs::MiscCmd::ConstPtr &msg)
Definition: DbwNode.cpp:877
void faultWatchdog(bool fault, uint8_t src, bool braking)
Definition: DbwNode.cpp:1191
NewEagle::Dbc dbwDbc_
Definition: DbwNode.h:208
ros::Publisher pub_sys_enable_
Definition: DbwNode.h:199
ros::Subscriber sub_global_enable_
Definition: DbwNode.h:182
void recvCAN(const can_msgs::Frame::ConstPtr &msg)
Definition: DbwNode.cpp:158
void recvCanImu(const std::vector< can_msgs::Frame::ConstPtr > &msgs)
ros::Publisher pub_driver_input_
Definition: DbwNode.h:200
sensor_msgs::JointState joint_state_
Definition: DbwNode.h:157
ros::Publisher pub_fault_actions_report_
Definition: DbwNode.h:205
void recvAcceleratorPedalCmd(const dbw_pacifica_msgs::AcceleratorPedalCmd::ConstPtr &msg)
Definition: DbwNode.cpp:722
ros::Publisher pub_misc_
Definition: DbwNode.h:190
void recvDisable(const std_msgs::Empty::ConstPtr &msg)
Definition: DbwNode.cpp:153
ros::Publisher pub_wheel_speeds_
Definition: DbwNode.h:191
ros::Subscriber sub_gear_
Definition: DbwNode.h:180
void timeoutAcceleratorPedal(bool timeout, bool enabled)
Definition: DbwNode.cpp:1109
ros::Publisher pub_steering_2_report_
Definition: DbwNode.h:204
void faultSteeringCal(bool fault)
Definition: DbwNode.cpp:1175
ros::Publisher pub_brake_
Definition: DbwNode.h:186
void overrideSteering(bool override)
Definition: DbwNode.cpp:1068
ros::Publisher pub_imu_
Definition: DbwNode.h:195
ros::Publisher pdu1_relay_pub_
Definition: DbwNode.h:212
ros::Publisher pub_low_voltage_system_
Definition: DbwNode.h:201
ros::Subscriber sub_accelerator_pedal_
Definition: DbwNode.h:178
void timeoutSteering(bool timeout, bool enabled)
Definition: DbwNode.cpp:1118
void timerCallback(const ros::TimerEvent &event)
Definition: DbwNode.cpp:940
ros::Subscriber sub_brake_
Definition: DbwNode.h:177
void timeoutBrake(bool timeout, bool enabled)
Definition: DbwNode.cpp:1100
ros::Subscriber sub_misc_
Definition: DbwNode.h:181
void recvGlobalEnableCmd(const dbw_pacifica_msgs::GlobalEnableCmd::ConstPtr &msg)
Definition: DbwNode.cpp:848
std::string dbcFile_
Definition: DbwNode.h:209
void recvEnable(const std_msgs::Empty::ConstPtr &msg)
Definition: DbwNode.cpp:148
ros::Subscriber sub_disable_
Definition: DbwNode.h:175
void overrideAcceleratorPedal(bool override)
Definition: DbwNode.cpp:1052
ros::Subscriber sub_steering_
Definition: DbwNode.h:179
ros::Publisher pub_wheel_positions_
Definition: DbwNode.h:192
ros::Publisher pub_joint_states_
Definition: DbwNode.h:196
void recvCanGps(const std::vector< can_msgs::Frame::ConstPtr > &msgs)
void faultBrakes(bool fault)
Definition: DbwNode.cpp:1127
std::string frame_id_
Definition: DbwNode.h:163
DbwNode(ros::NodeHandle &node, ros::NodeHandle &priv_nh)
Definition: DbwNode.cpp:42
ros::Publisher pub_vin_
Definition: DbwNode.h:198
void overrideGear(bool override)
Definition: DbwNode.cpp:1084
ros::Publisher pub_hmi_global_enable_report_
Definition: DbwNode.h:206
ros::Publisher pub_tire_pressure_
Definition: DbwNode.h:193
ros::Subscriber sub_enable_
Definition: DbwNode.h:174
void recvSteeringCmd(const dbw_pacifica_msgs::SteeringCmd::ConstPtr &msg)
Definition: DbwNode.cpp:774
void faultAcceleratorPedal(bool fault)
Definition: DbwNode.cpp:1143
ros::Publisher pub_surround_
Definition: DbwNode.h:194
ros::Publisher pub_can_
Definition: DbwNode.h:185
void faultSteering(bool fault)
Definition: DbwNode.cpp:1159
void overrideBrake(bool override)
Definition: DbwNode.cpp:1036
ros::Publisher pub_gear_
Definition: DbwNode.h:189
ros::Publisher pub_steering_
Definition: DbwNode.h:188
void recvBrakeCmd(const dbw_pacifica_msgs::BrakeCmd::ConstPtr &msg)
Definition: DbwNode.cpp:682
ros::Publisher pub_twist_
Definition: DbwNode.h:197
ros::Publisher pub_accel_pedal_
Definition: DbwNode.h:187


dbw_pacifica_can
Author(s): Ryan Borchert
autogenerated on Fri Mar 20 2020 03:31:38