caster_hardware_socketcan.h
Go to the documentation of this file.
1 #ifndef CASTER_HARDWARE_SOCKETCAN_H_
2 #define CASTER_HARDWARE_SOCKETCAN_H_
3 
4 #include <string>
5 
6 #include <cstdlib>
7 #include <cstring>
8 
9 #include <sys/types.h>
10 
11 #include <ros/ros.h>
12 #include <can_msgs/Frame.h>
13 #include <sensor_msgs/JointState.h>
15 
16 #include <diagnostic_updater/diagnostic_updater.h>
17 
21 
22 #include <caster_base/SetDigitalOutput.h>
23 
24 #define REDUCTION_RATIO 15.0
25 
26 #define CANBUS_BASE_FRAME_FORMAT 0b00000000
27 #define CANBUS_EXTENDED_FRAME_FORMAT 0b10000000
28 #define CANBUS_REMOTE_FRAME 0b00000000
29 #define CANBUS_DATA_FRAME 0b01000000
30 
31 namespace iqr {
36  public:
38 
39  bool Connect();
40  void Initialize(std::string node_name, ros::NodeHandle& nh, ros::NodeHandle& private_nh);
41 
42  void UpdateHardwareStatus();
44 
45  void Clear();
46 
47  enum MotorIndex {
48  kLeftMotor = 0x00,
49  kRightMotor = 0x01,
50  };
51 
53  kCommand = 0x02,
54  kQuery = 0x04,
57  };
58 
60  /* runtime commands */
61  kSetVelocity = 0x2002,
62  kSetBLCounter = 0x2004,
63  kSetIndividualDO = 0x2009,
65 
66  /* runtime queries */
67  kReadMotorAmps = 0x2100,
69  kReadBLMotorRPM = 0x210A,
70  kReadStatusFlags = 0x2111,
71  kReadFaultFlags = 0x2112,
73  };
74 
75  struct MotorStatus {
76  float current;
77  int16_t rpm;
78  int32_t counter;
79  int32_t counter_offset;
80  uint8_t status;
82 
84  rpm(0), counter(0), status(0), counter_reset(false)
85  { }
86  };
87 
88  private:
89  void ResetTravelOffset();
91 
92  std::string ToBinary(size_t data, uint8_t length);
93 
94  bool Command(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint32_t data, uint8_t data_length);
95  bool Query(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint8_t data_length);
96  void SendCanOpenData(uint32_t node_id, RoboteqClientCommandType type, RoboteqCanOpenObjectDictionary index, uint8_t sub_index, uint32_t data, uint8_t data_length);
97 
98  void CanReceiveCallback(const can_msgs::Frame::ConstPtr& msg);
99 
101 
102  void LeftMotorCheck(diagnostic_updater::DiagnosticStatusWrapper& status);
103  void RightMotorCheck(diagnostic_updater::DiagnosticStatusWrapper& status);
104  void StatusCheck(diagnostic_updater::DiagnosticStatusWrapper& status);
105  void ControllerCheck(diagnostic_updater::DiagnosticStatusWrapper& status);
106 
107  bool SetDigitalOutputCB(caster_base::SetDigitalOutput::Request &req, caster_base::SetDigitalOutput::Response &res);
108 
109  std::string node_name_;
110 
113 
116 
118 
121 
123 
124  // ROS Control interfaces
127 
128  // diagnostic update
129  diagnostic_updater::Updater diagnostic_updater_;
130 
131  // digital output service
133 
134  int can_id_;
135 
136  // ROS Parameters
138 
139  int8_t fault_flags_;
142 
146  struct Joint {
147  double position;
149  double velocity;
150  double effort;
152 
153  Joint() :
154  position(0), velocity(0), effort(0), velocity_command(0)
155  { }
156  } joints_[2];
157 };
158 } // namespace iqr
159 #endif // CASTER_HARDWARE_SOCKETCAN_H_
bool Query(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint8_t data_length)
void ControllerCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
std::string ToBinary(size_t data, uint8_t length)
void Initialize(std::string node_name, ros::NodeHandle &nh, ros::NodeHandle &private_nh)
ros::ServiceServer set_io_service_
diagnostic_updater::Updater diagnostic_updater_
void CanReceiveCallback(const can_msgs::Frame::ConstPtr &msg)
void StatusCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
void ControllerTimerCallback(const ros::TimerEvent &)
void RightMotorCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
_u32 type
bool SetDigitalOutputCB(caster_base::SetDigitalOutput::Request &req, caster_base::SetDigitalOutput::Response &res)
hardware_interface::JointStateInterface joint_state_interface_
bool Command(RoboteqCanOpenObjectDictionary query, uint8_t sub_index, uint32_t data, uint8_t data_length)
struct iqr::CasterHardware::Joint joints_[2]
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
_u8 data[0]
hardware_interface::VelocityJointInterface velocity_joint_interface_
void LeftMotorCheck(diagnostic_updater::DiagnosticStatusWrapper &status)
void SendCanOpenData(uint32_t node_id, RoboteqClientCommandType type, RoboteqCanOpenObjectDictionary index, uint8_t sub_index, uint32_t data, uint8_t data_length)
controller_manager::ControllerManager * controller_manager_


caster_base
Author(s): Ye Tian
autogenerated on Wed Dec 18 2019 03:34:39