motor_hardware.h
Go to the documentation of this file.
1 
31 #ifndef MOTORHARDWARE_H
32 #define MOTORHARDWARE_H
33 
37 #include "ros/ros.h"
38 #include "sensor_msgs/JointState.h"
39 
40 #include "std_msgs/Int32.h"
41 #include "std_msgs/UInt32.h"
42 #include "std_msgs/Float32.h"
43 #include "std_msgs/Bool.h"
44 #include "std_msgs/String.h"
45 #include "sensor_msgs/BatteryState.h"
46 #include "ubiquity_motor/MotorState.h"
47 
50 
53 
54 #include <gtest/gtest_prod.h>
55 
56 // Mininum hardware versions required for various features
57 #define MIN_HW_OPTION_SWITCH 50
58 
62  diagnostic_updater::FrequencyStatusParam(&odom_min_freq, &odom_max_freq)) {}
63  // Communication Statuses
65  int firmware_date = 0;
67 
68  // These are for diagnostic topic output
70  int fw_pid_integral = 0;
72  int fw_pid_control = 0;
73  int fw_pid_velocity = 0;
76  int fw_max_pwm = 0;
77 
78  double odom_max_freq = 1000;
79  double odom_min_freq = 50;
81 
82  // Limits
83  bool left_pwm_limit = false;
84  bool right_pwm_limit = false;
85  bool left_integral_limit = false;
86  bool right_integral_limit = false;
87  bool left_max_speed_limit = false;
88  bool right_max_speed_limit = false;
90 
91  // Power supply statuses
92  float battery_voltage = 0.0;
95 
96  // Wheel current states
97  double motorCurrentLeft = 0.0;
98  double motorCurrentRight = 0.0;
99 
100  // ADC count for zero current. We could calibrate this if required.
101  // Nominally 1024 and goes up from there this lower value is used.
102  double motorAmpsZeroAdcCount = 1015;
103 
106 
107  /* For later implementation (firmware support)
108  bool main_5V_error = false;
109  bool main_5V_ol = false;
110  bool main_12V_error = false;
111  bool main_12V_ol = false;
112  bool aux_5V_error = false;
113  bool aux_5V_ol = false;
114  bool aux_12V_error = false;
115  bool aux_12V_ol = false;
116  */
117 
118  bool estop_motor_power_off = false; // for Diagnostic reporting of ESTOP switch
119 
131 };
132 
134 public:
135  MotorHardware(ros::NodeHandle nh, NodeParams node_params, CommsParams serial_params,
136  FirmwareParams firmware_params);
137  virtual ~MotorHardware();
138  void closePort();
139  bool openPort();
140  void clearCommands();
141  void readInputs(uint32_t index);
142  void writeSpeeds();
143  void writeSpeedsInRadians(double left_radians, double right_radians);
144  void publishFirmwareInfo();
145  float calculateBatteryPercentage(float voltage, int cells, const float* type);
146  int areWheelSpeedsLower(double wheelSpeedRadPerSec);
147  void requestFirmwareVersion();
148  void requestFirmwareDate();
149  void setParams(FirmwareParams firmware_params);
150  void sendParams();
151  void forcePidParamUpdates();
152  float getBatteryVoltage(void);
153  void setDeadmanTimer(int32_t deadman);
154  void setDeadzoneEnable(int32_t deadzone_enable);
155  void setDebugLeds(bool led1, bool led2);
156  void setHardwareVersion(int32_t hardware_version);
158  void setEstopDetection(int32_t estop_detection);
159  bool getEstopState(void);
160  void setMaxFwdSpeed(int32_t max_speed_fwd);
161  void setMaxRevSpeed(int32_t max_speed_rev);
162  void setMaxPwm(int32_t max_pwm);
163  void setWheelType(int32_t wheel_type);
164  void setWheelGearRatio(double wheel_gear_ratio);
165  double getWheelGearRatio(void);
166  double getWheelTicksPerRadian(void);
167  void setDriveType(int32_t drive_type);
168  void setPidControl(int32_t pid_control);
169  void nullWheelErrors(void);
170  void setWheelDirection(int32_t wheel_direction);
171  void getMotorCurrents(double &currentLeft, double &currentRight);
172  int getOptionSwitch(void);
173  int getPidControlWord(void);
174  void setOptionSwitchReg(int32_t option_switch);
175  void requestSystemEvents();
176  void setSystemEvents(int32_t system_events);
177  void getWheelJointPositions(double &leftWheelPosition, double &rightWheelPosition);
178  void setWheelJointVelocities(double leftWheelVelocity, double rightWheelVelocity);
179  void publishMotorState(void);
183  int num_fw_params; // This is used for sendParams as modulo count
188  int max_pwm;
195 
196 
198 private:
199  void _addOdometryRequest(std::vector<MotorMessage>& commands) const;
200  void _addVelocityRequest(std::vector<MotorMessage>& commands) const;
201 
202  int16_t calculateSpeedFromRadians(double radians);
203  double calculateRadiansFromTicks(int16_t ticks);
204 
207 
210 
211  int32_t deadman_timer;
212 
213  double ticks_per_radian; // Odom ticks per radian for wheel encoders in use
214 
215  int32_t sendPid_count;
216 
217  bool estop_motor_power_off; // Motor power inactive, most likely from ESTOP switch
218 
219  struct Joint {
220  double position;
221  double velocity;
222  double effort;
224 
226  } joints_[2];
227 
228  // MessageTypes enum for refering to motor or wheel number
230  Motor_M1 = 1,
232  };
233 
234  // MessageTypes enum in class to avoid global namespace pollution
236  Left = 0,
237  Right = 1
238  };
239 
242 
245 
248 
253 
255 
257 
258  FRIEND_TEST(MotorHardwareTests, nonZeroWriteSpeedsOutputs);
259  FRIEND_TEST(MotorHardwareTests, odomUpdatesPosition);
260  FRIEND_TEST(MotorHardwareTests, odomUpdatesPositionMax);
261 };
262 
263 #endif
MotorDiagnostics::motorAmpsZeroAdcCount
double motorAmpsZeroAdcCount
Definition: motor_hardware.h:102
MotorHardware::getWheelGearRatio
double getWheelGearRatio(void)
Definition: motor_hardware.cc:783
MotorDiagnostics::battery_voltage_low_level
float battery_voltage_low_level
Definition: motor_hardware.h:93
diagnostic_updater::FrequencyStatus
MotorHardware::estop_motor_power_off
bool estop_motor_power_off
Definition: motor_hardware.h:217
MotorDiagnostics::motor_pid_p_status
void motor_pid_p_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1219
MotorDiagnostics::battery_status
void battery_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1205
MotorHardware::getWheelTicksPerRadian
double getWheelTicksPerRadian(void)
Definition: motor_hardware.cc:788
MotorHardware::num_fw_params
int num_fw_params
Definition: motor_hardware.h:183
MotorHardware::setSystemEvents
void setSystemEvents(int32_t system_events)
Definition: motor_hardware.cc:892
MotorHardware::setWheelDirection
void setWheelDirection(int32_t wheel_direction)
Definition: motor_hardware.cc:843
MotorHardware::nullWheelErrors
void nullWheelErrors(void)
Definition: motor_hardware.cc:832
MotorHardware::clearCommands
void clearCommands()
Definition: motor_hardware.cc:223
MotorDiagnostics::firmware_date
int firmware_date
Definition: motor_hardware.h:65
MotorHardware::calculateRadiansFromTicks
double calculateRadiansFromTicks(int16_t ticks)
Definition: motor_hardware.cc:1133
MotorHardwareTests
Definition: motor_hardware_test.cc:14
ros::Publisher
MotorHardware::max_speed_rev
int max_speed_rev
Definition: motor_hardware.h:187
MotorHardware::calculateSpeedFromRadians
int16_t calculateSpeedFromRadians(double radians)
Definition: motor_hardware.cc:1116
MotorHardware::wheel_type
int wheel_type
Definition: motor_hardware.h:192
MotorHardware::firmware_options
int firmware_options
Definition: motor_hardware.h:182
MotorHardware::setDeadmanTimer
void setDeadmanTimer(int32_t deadman)
Definition: motor_hardware.cc:921
MotorDiagnostics::left_max_speed_limit
bool left_max_speed_limit
Definition: motor_hardware.h:87
MotorHardware::sendParams
void sendParams()
Definition: motor_hardware.cc:967
MotorHardware::setDebugLeds
void setDebugLeds(bool led1, bool led2)
Definition: motor_hardware.cc:1087
MotorHardware::setParams
void setParams(FirmwareParams firmware_params)
Definition: motor_hardware.cc:939
MotorDiagnostics::firmware_options
int firmware_options
Definition: motor_hardware.h:66
MotorDiagnostics::left_pwm_limit
bool left_pwm_limit
Definition: motor_hardware.h:83
hardware_interface::JointStateInterface
MotorHardware::setPidControl
void setPidControl(int32_t pid_control)
Definition: motor_hardware.cc:821
MotorDiagnostics::motorCurrentLeft
double motorCurrentLeft
Definition: motor_hardware.h:97
ros.h
MotorHardware::Joint::velocity_command
double velocity_command
Definition: motor_hardware.h:223
MotorHardware::Right
@ Right
Definition: motor_hardware.h:237
MotorDiagnostics::battery_voltage_critical
float battery_voltage_critical
Definition: motor_hardware.h:94
MotorDiagnostics
Definition: motor_hardware.h:59
MotorHardware::motor_serial_
MotorSerial * motor_serial_
Definition: motor_hardware.h:254
MotorHardware::closePort
void closePort()
Definition: motor_hardware.cc:214
MotorSerial
Definition: motor_serial.h:43
motor_parameters.h
diagnostic_updater::Updater
MotorHardware::MotorOrWheelNumber
MotorOrWheelNumber
Definition: motor_hardware.h:229
MotorHardware::Joint::position
double position
Definition: motor_hardware.h:220
MotorHardware::getEstopState
bool getEstopState(void)
Definition: motor_hardware.cc:748
MotorHardware::setDriveType
void setDriveType(int32_t drive_type)
Definition: motor_hardware.cc:811
MotorDiagnostics::battery_voltage
float battery_voltage
Definition: motor_hardware.h:92
MotorHardware::MotorHardware
MotorHardware(ros::NodeHandle nh, NodeParams node_params, CommsParams serial_params, FirmwareParams firmware_params)
Definition: motor_hardware.cc:116
MotorHardware::areWheelSpeedsLower
int areWheelSpeedsLower(double wheelSpeedRadPerSec)
Definition: motor_hardware.cc:664
MotorHardware::drive_type
int drive_type
Definition: motor_hardware.h:194
MotorDiagnostics::fw_pid_control
int fw_pid_control
Definition: motor_hardware.h:72
MotorHardware::_addVelocityRequest
void _addVelocityRequest(std::vector< MotorMessage > &commands) const
MotorDiagnostics::right_pwm_limit
bool right_pwm_limit
Definition: motor_hardware.h:84
MotorHardware::publishMotorState
void publishMotorState(void)
Definition: motor_hardware.cc:245
MotorDiagnostics::fw_pid_denominator
int fw_pid_denominator
Definition: motor_hardware.h:74
MotorHardware::openPort
bool openPort()
Definition: motor_hardware.cc:219
MotorHardware::leftError
ros::Publisher leftError
Definition: motor_hardware.h:240
MotorHardware::~MotorHardware
virtual ~MotorHardware()
Definition: motor_hardware.cc:210
MotorHardware::setHardwareVersion
void setHardwareVersion(int32_t hardware_version)
Definition: motor_hardware.cc:717
MotorHardware::rightCurrent
ros::Publisher rightCurrent
Definition: motor_hardware.h:244
MotorHardware::wheel_gear_ratio
double wheel_gear_ratio
Definition: motor_hardware.h:193
MotorDiagnostics::fw_pid_velocity
int fw_pid_velocity
Definition: motor_hardware.h:73
MotorHardware::getPidControlWord
int getPidControlWord(void)
Definition: motor_hardware.cc:853
diagnostic_updater.h
MotorHardware::writeSpeeds
void writeSpeeds()
Definition: motor_hardware.cc:653
MotorDiagnostics::motorPwmDriveRight
int motorPwmDriveRight
Definition: motor_hardware.h:105
MotorHardware::getWheelJointPositions
void getWheelJointPositions(double &leftWheelPosition, double &rightWheelPosition)
Definition: motor_hardware.cc:230
MotorHardware::setDeadzoneEnable
void setDeadzoneEnable(int32_t deadzone_enable)
Definition: motor_hardware.cc:930
MotorHardware::motor_power_active
ros::Publisher motor_power_active
Definition: motor_hardware.h:251
MotorDiagnostics::fw_pid_derivative
int fw_pid_derivative
Definition: motor_hardware.h:71
MotorHardware::ticks_per_radian
double ticks_per_radian
Definition: motor_hardware.h:213
MotorHardware::motor_diag_
MotorDiagnostics motor_diag_
Definition: motor_hardware.h:256
hardware_interface::VelocityJointInterface
MotorHardware::getBatteryVoltage
float getBatteryVoltage(void)
Definition: motor_hardware.cc:1083
MotorHardware::readInputs
void readInputs(uint32_t index)
Definition: motor_hardware.cc:268
MotorDiagnostics::right_max_speed_limit
bool right_max_speed_limit
Definition: motor_hardware.h:88
MotorDiagnostics::estop_motor_power_off
bool estop_motor_power_off
Definition: motor_hardware.h:118
MotorHardware::calculateBatteryPercentage
float calculateBatteryPercentage(float voltage, int cells, const float *type)
Definition: motor_hardware.cc:584
MotorHardware::joint_state_interface_
hardware_interface::JointStateInterface joint_state_interface_
Definition: motor_hardware.h:205
MotorHardware::velocity_joint_interface_
hardware_interface::VelocityJointInterface velocity_joint_interface_
Definition: motor_hardware.h:206
joint_command_interface.h
MotorHardware::max_speed_fwd
int max_speed_fwd
Definition: motor_hardware.h:186
MotorHardware::Joint::Joint
Joint()
Definition: motor_hardware.h:225
hardware_interface::RobotHW
CommsParams
Definition: motor_parameters.h:175
diagnostic_updater
MotorDiagnostics::left_integral_limit
bool left_integral_limit
Definition: motor_hardware.h:85
motor_serial.h
MotorDiagnostics::firmware_status
void firmware_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1144
MotorDiagnostics::firmware_version
int firmware_version
Definition: motor_hardware.h:64
MotorHardware::requestSystemEvents
void requestSystemEvents()
Definition: motor_hardware.cc:698
MotorDiagnostics::fw_pid_moving_buffer_size
int fw_pid_moving_buffer_size
Definition: motor_hardware.h:75
MotorHardware::hardware_version
int hardware_version
Definition: motor_hardware.h:184
MotorHardware::Motor_M2
@ Motor_M2
Definition: motor_hardware.h:231
MotorHardware::system_events
int system_events
Definition: motor_hardware.h:191
MotorHardware::getOptionSwitch
int getOptionSwitch(void)
Definition: motor_hardware.cc:862
MotorHardware::max_pwm
int max_pwm
Definition: motor_hardware.h:188
MotorHardware::Left
@ Left
Definition: motor_hardware.h:236
MotorHardware::setMaxRevSpeed
void setMaxRevSpeed(int32_t max_speed_rev)
Definition: motor_hardware.cc:902
MotorHardware::publishFirmwareInfo
void publishFirmwareInfo()
Definition: motor_hardware.cc:560
MotorDiagnostics::odom_max_freq
double odom_max_freq
Definition: motor_hardware.h:78
MotorHardware
Definition: motor_hardware.h:133
MotorHardware::setWheelType
void setWheelType(int32_t wheel_type)
Definition: motor_hardware.cc:764
MotorHardware::setOptionSwitchReg
void setOptionSwitchReg(int32_t option_switch)
Definition: motor_hardware.cc:882
MotorHardware::pid_control
int pid_control
Definition: motor_hardware.h:189
MotorHardware::setMaxFwdSpeed
void setMaxFwdSpeed(int32_t max_speed_fwd)
Definition: motor_hardware.cc:753
MotorHardware::sendPid_count
int32_t sendPid_count
Definition: motor_hardware.h:215
MotorHardware::forcePidParamUpdates
void forcePidParamUpdates()
Definition: motor_hardware.cc:954
MotorHardware::setEstopDetection
void setEstopDetection(int32_t estop_detection)
Definition: motor_hardware.cc:738
MotorDiagnostics::motor_power_status
void motor_power_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1241
MotorDiagnostics::fw_pid_integral
int fw_pid_integral
Definition: motor_hardware.h:70
MotorHardware::deadman_enable
int deadman_enable
Definition: motor_hardware.h:190
MotorDiagnostics::firmware_date_status
void firmware_date_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1157
MotorHardware::requestFirmwareVersion
void requestFirmwareVersion()
Definition: motor_hardware.cc:680
MotorHardware::requestFirmwareDate
void requestFirmwareDate()
Definition: motor_hardware.cc:689
MotorHardware::Joint::effort
double effort
Definition: motor_hardware.h:222
joint_state_interface.h
update_functions.h
MotorHardware::setMaxPwm
void setMaxPwm(int32_t max_pwm)
Definition: motor_hardware.cc:912
MotorHardware::diag_updater
diagnostic_updater::Updater diag_updater
Definition: motor_hardware.h:197
MotorHardware::getMotorCurrents
void getMotorCurrents(double &currentLeft, double &currentRight)
Definition: motor_hardware.cc:707
MotorHardware::setWheelJointVelocities
void setWheelJointVelocities(double leftWheelVelocity, double rightWheelVelocity)
Definition: motor_hardware.cc:238
MotorHardware::deadman_timer
int32_t deadman_timer
Definition: motor_hardware.h:211
MotorDiagnostics::fw_max_pwm
int fw_max_pwm
Definition: motor_hardware.h:76
FirmwareParams
Definition: motor_parameters.h:57
MotorHardware::rightError
ros::Publisher rightError
Definition: motor_hardware.h:241
MotorDiagnostics::MotorDiagnostics
MotorDiagnostics()
Definition: motor_hardware.h:60
MotorHardware::firmware_state
ros::Publisher firmware_state
Definition: motor_hardware.h:249
MotorHardware::_addOdometryRequest
void _addOdometryRequest(std::vector< MotorMessage > &commands) const
NodeParams
Definition: motor_parameters.h:193
MotorHardware::WheelJointLocation
WheelJointLocation
Definition: motor_hardware.h:235
MotorDiagnostics::odom_min_freq
double odom_min_freq
Definition: motor_hardware.h:79
MotorHardware::Joint::velocity
double velocity
Definition: motor_hardware.h:221
MotorHardware::estop_pid_threshold
int estop_pid_threshold
Definition: motor_hardware.h:185
MotorHardware::setWheelGearRatio
void setWheelGearRatio(double wheel_gear_ratio)
Definition: motor_hardware.cc:796
MotorHardware::Motor_M1
@ Motor_M1
Definition: motor_hardware.h:230
MotorHardware::fw_params
FirmwareParams fw_params
Definition: motor_hardware.h:208
MotorHardware::leftCurrent
ros::Publisher leftCurrent
Definition: motor_hardware.h:243
MotorDiagnostics::fw_pid_proportional
int fw_pid_proportional
Definition: motor_hardware.h:69
diagnostic_updater::DiagnosticStatusWrapper
robot_hw.h
MotorDiagnostics::motorPwmDriveLeft
int motorPwmDriveLeft
Definition: motor_hardware.h:104
MotorHardware::Joint
Definition: motor_hardware.h:219
MotorHardware::motor_state
ros::Publisher motor_state
Definition: motor_hardware.h:252
MotorHardware::battery_state
ros::Publisher battery_state
Definition: motor_hardware.h:250
MotorHardware::firmware_version
int firmware_version
Definition: motor_hardware.h:180
MotorDiagnostics::motorCurrentRight
double motorCurrentRight
Definition: motor_hardware.h:98
MotorHardware::firmware_date
int firmware_date
Definition: motor_hardware.h:181
MotorDiagnostics::motor_max_pwm_status
void motor_max_pwm_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1235
MotorDiagnostics::right_integral_limit
bool right_integral_limit
Definition: motor_hardware.h:86
MotorDiagnostics::motor_pid_d_status
void motor_pid_d_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1227
MotorHardware::rightTickInterval
ros::Publisher rightTickInterval
Definition: motor_hardware.h:247
MotorDiagnostics::motor_pid_v_status
void motor_pid_v_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1231
MotorDiagnostics::firmware_options_status
void firmware_options_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1253
MotorDiagnostics::param_limit_in_firmware
bool param_limit_in_firmware
Definition: motor_hardware.h:89
MotorHardware::FRIEND_TEST
FRIEND_TEST(MotorHardwareTests, nonZeroWriteSpeedsOutputs)
MotorHardware::leftTickInterval
ros::Publisher leftTickInterval
Definition: motor_hardware.h:246
MotorDiagnostics::limit_status
void limit_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1172
MotorDiagnostics::odom_update_status
diagnostic_updater::FrequencyStatus odom_update_status
Definition: motor_hardware.h:80
ros::NodeHandle
MotorHardware::writeSpeedsInRadians
void writeSpeedsInRadians(double left_radians, double right_radians)
Definition: motor_hardware.cc:616
MotorHardware::setEstopPidThreshold
void setEstopPidThreshold(int32_t estop_pid_threshold)
Definition: motor_hardware.cc:728
MotorDiagnostics::motor_pid_i_status
void motor_pid_i_status(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: motor_hardware.cc:1223
MotorHardware::joints_
struct MotorHardware::Joint joints_[2]
MotorHardware::prev_fw_params
FirmwareParams prev_fw_params
Definition: motor_hardware.h:209


ubiquity_motor
Author(s):
autogenerated on Thu Nov 16 2023 03:30:55