motor_parameters.h
Go to the documentation of this file.
1 
31 #ifndef UBIQUITY_MOTOR_MOTOR_PARMETERS_H
32 #define UBIQUITY_MOTOR_MOTOR_PARMETERS_H
33 
34 #include <ros/ros.h>
35 
36 // These defines are for a high level topic for control of the motor node at a system level
37 #define ROS_TOPIC_SYSTEM_CONTROL "system_control" // A topic for system level control commands
38 #define MOTOR_CONTROL_CMD "motor_control" // A mnumonic for a motor control system command
39 #define MOTOR_CONTROL_ENABLE "enable" // Parameter for MOTOR_CONTROL_CMD to enable control
40 #define MOTOR_CONTROL_DISABLE "disable" // Parameter for MOTOR_CONTROL_CMD to enable control
41 #define MOTOR_SPEED_CONTROL_CMD "speed_control" // A mnumonic for disable of speed to avoid colision
42 
43 // The gear ratio defaults for wheels shipped with Magni
44 #define WHEEL_GEAR_RATIO_1 ((double)(4.294)) // Default original motor gear ratio for Magni
45 #define WHEEL_GEAR_RATIO_2 ((double)(5.170)) // 2nd version standard Magni wheels gear ratio
46 
47 template <typename T>
48 T getParamOrDefault(ros::NodeHandle nh, std::string parameter_name,
49  T default_val) {
50  T value = default_val;
51  if (!nh.getParam(parameter_name, value)) {
52  nh.setParam(parameter_name, value);
53  }
54  return value;
55 }
56 
59  int32_t pid_integral;
60  int32_t pid_derivative;
61  int32_t pid_velocity;
62  int32_t pid_denominator;
64  int32_t pid_control;
66  int32_t estop_detection;
68  int32_t max_speed_fwd;
69  int32_t max_speed_rev;
70  int32_t max_pwm;
71  int32_t deadman_timer;
72  int32_t deadzone_enable;
73  int32_t hw_options;
74  int32_t option_switch;
75  int32_t system_events;
80 
82  : pid_proportional(4000),
83  pid_integral(5),
84  pid_derivative(-200),
85  pid_velocity(0),
86  pid_denominator(1000),
88  pid_control(0),
90  estop_detection(1),
91  estop_pid_threshold(1500),
92  max_speed_fwd(80),
93  max_speed_rev(-80),
94  max_pwm(250),
95  deadman_timer(2400000),
96  deadzone_enable(0),
97  hw_options(0),
98  option_switch(0),
99  system_events(0),
100 
101  // ADC uses Vcc/2 for 2048 counts. We feed in battery with a 1/21 ratio
102  // So for 5.00V mult=0.05127 When Vcc=5.16V (Pi4 mod) mult = 0.0529
106  battery_voltage_critical(22.5){};
107 
109  : pid_proportional(4000),
110  pid_integral(5),
111  pid_derivative(-200),
112  pid_velocity(0),
113  pid_denominator(1000),
115  pid_control(0),
117  estop_detection(1),
118  estop_pid_threshold(1500),
119  max_speed_fwd(80),
120  max_speed_rev(-80),
121  max_pwm(250),
122  deadman_timer(2400000),
123  deadzone_enable(0),
124  hw_options(0),
125  option_switch(0),
126  system_events(0),
127  battery_voltage_multiplier(0.05127), // See note above for this multiplier
131  {
132  // clang-format off
134  nh, "ubiquity_motor/pid_proportional", pid_proportional);
136  nh, "ubiquity_motor/pid_integral", pid_integral);
138  nh, "ubiquity_motor/pid_derivative", pid_derivative);
140  nh, "ubiquity_motor/pid_velocity", pid_velocity);
142  nh, "ubiquity_motor/pid_denominator", pid_denominator);
144  nh, "ubiquity_motor/pid_control", pid_control);
146  nh, "ubiquity_motor/window_size", pid_moving_buffer_size);
148  nh, "ubiquity_motor/controller_board_version", controller_board_version);
150  nh, "ubiquity_motor/fw_estop_detection", estop_detection);
152  nh, "ubiquity_motor/fw_estop_pid_threshold", estop_pid_threshold);
154  nh, "ubiquity_motor/fw_max_speed_fwd", max_speed_fwd);
156  nh, "ubiquity_motor/fw_max_speed_rev", max_speed_rev);
158  nh, "ubiquity_motor/fw_max_pwm", max_pwm);
160  nh, "ubiquity_motor/deadman_timer", deadman_timer);
162  nh, "ubiquity_motor/deadzone_enable", deadzone_enable);
164  nh, "ubiquity_motor/battery_voltage_offset", battery_voltage_offset);
166  nh, "ubiquity_motor/battery_voltage_multiplier", battery_voltage_multiplier);
168  nh, "ubiquity_motor/battery_voltage_low_level", battery_voltage_low_level);
170  nh, "ubiquity_motor/battery_voltage_critical", battery_voltage_critical);
171  // clang-format on
172  };
173 };
174 
175 struct CommsParams {
176  std::string serial_port;
177  int32_t baud_rate;
178 
180  : serial_port("/dev/ttyS0"), baud_rate(9600) {};
181 
183  : serial_port("/dev/ttyS0"), baud_rate(9600) {
184  // clang-format off
186  nh, "ubiquity_motor/serial_port", serial_port);
188  nh, "ubiquity_motor/serial_baud", baud_rate);
189  // clang-format on
190  };
191 };
192 
193 struct NodeParams {
195  std::string wheel_type;
196  std::string wheel_direction;
198  std::string drive_type;
199 
200  int mcbControlEnabled; // State to allow suspension of MCB serial control for diagnostic purposes
201  int mcbSpeedEnabled; // State to allow zero speed override for safety reasons
202 
204  wheel_type("firmware_default"),
205  wheel_direction("firmware_default"),
207  drive_type("firmware_default"),
209  mcbSpeedEnabled(1){};
210 
212  wheel_type("firmware_default"),
213  wheel_direction("firmware_default"),
215  drive_type("firmware_default"),
217  mcbSpeedEnabled(1) {
218  // clang-format off
220  nh, "ubiquity_motor/controller_loop_rate", controller_loop_rate);
222  nh, "ubiquity_motor/wheel_type", wheel_type);
224  nh, "ubiquity_motor/wheel_direction", wheel_direction);
226  nh, "ubiquity_motor/wheel_gear_ratio", wheel_gear_ratio);
228  nh, "ubiquity_motor/drive_type", drive_type);
229  // clang-format on
230  };
231 };
232 
233 #endif // UBIQUITY_MOTOR_MOTOR_PARMETERS_H
NodeParams::wheel_type
std::string wheel_type
Definition: motor_parameters.h:195
ros::NodeHandle::setParam
void setParam(const std::string &key, bool b) const
FirmwareParams::estop_detection
int32_t estop_detection
Definition: motor_parameters.h:66
FirmwareParams::FirmwareParams
FirmwareParams()
Definition: motor_parameters.h:81
FirmwareParams::battery_voltage_offset
float battery_voltage_offset
Definition: motor_parameters.h:77
FirmwareParams::pid_proportional
int32_t pid_proportional
Definition: motor_parameters.h:58
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
FirmwareParams::hw_options
int32_t hw_options
Definition: motor_parameters.h:73
ros.h
NodeParams::controller_loop_rate
double controller_loop_rate
Definition: motor_parameters.h:194
FirmwareParams::pid_control
int32_t pid_control
Definition: motor_parameters.h:64
getParamOrDefault
T getParamOrDefault(ros::NodeHandle nh, std::string parameter_name, T default_val)
Definition: motor_parameters.h:48
FirmwareParams::battery_voltage_critical
float battery_voltage_critical
Definition: motor_parameters.h:79
NodeParams::wheel_direction
std::string wheel_direction
Definition: motor_parameters.h:196
NodeParams::drive_type
std::string drive_type
Definition: motor_parameters.h:198
FirmwareParams::pid_velocity
int32_t pid_velocity
Definition: motor_parameters.h:61
FirmwareParams::deadzone_enable
int32_t deadzone_enable
Definition: motor_parameters.h:72
CommsParams::baud_rate
int32_t baud_rate
Definition: motor_parameters.h:177
FirmwareParams::option_switch
int32_t option_switch
Definition: motor_parameters.h:74
FirmwareParams::battery_voltage_multiplier
float battery_voltage_multiplier
Definition: motor_parameters.h:76
NodeParams::NodeParams
NodeParams()
Definition: motor_parameters.h:203
FirmwareParams::battery_voltage_low_level
float battery_voltage_low_level
Definition: motor_parameters.h:78
WHEEL_GEAR_RATIO_1
#define WHEEL_GEAR_RATIO_1
Definition: motor_parameters.h:44
FirmwareParams::max_speed_rev
int32_t max_speed_rev
Definition: motor_parameters.h:69
CommsParams::CommsParams
CommsParams(ros::NodeHandle nh)
Definition: motor_parameters.h:182
FirmwareParams::max_speed_fwd
int32_t max_speed_fwd
Definition: motor_parameters.h:68
FirmwareParams::pid_derivative
int32_t pid_derivative
Definition: motor_parameters.h:60
CommsParams
Definition: motor_parameters.h:175
FirmwareParams::system_events
int32_t system_events
Definition: motor_parameters.h:75
FirmwareParams::estop_pid_threshold
int32_t estop_pid_threshold
Definition: motor_parameters.h:67
NodeParams::mcbSpeedEnabled
int mcbSpeedEnabled
Definition: motor_parameters.h:201
NodeParams::wheel_gear_ratio
double wheel_gear_ratio
Definition: motor_parameters.h:197
NodeParams::mcbControlEnabled
int mcbControlEnabled
Definition: motor_parameters.h:200
FirmwareParams::FirmwareParams
FirmwareParams(ros::NodeHandle nh)
Definition: motor_parameters.h:108
FirmwareParams::pid_integral
int32_t pid_integral
Definition: motor_parameters.h:59
FirmwareParams::controller_board_version
int32_t controller_board_version
Definition: motor_parameters.h:65
CommsParams::serial_port
std::string serial_port
Definition: motor_parameters.h:176
FirmwareParams
Definition: motor_parameters.h:57
NodeParams
Definition: motor_parameters.h:193
NodeParams::NodeParams
NodeParams(ros::NodeHandle nh)
Definition: motor_parameters.h:211
FirmwareParams::max_pwm
int32_t max_pwm
Definition: motor_parameters.h:70
CommsParams::CommsParams
CommsParams()
Definition: motor_parameters.h:179
FirmwareParams::pid_denominator
int32_t pid_denominator
Definition: motor_parameters.h:62
FirmwareParams::deadman_timer
int32_t deadman_timer
Definition: motor_parameters.h:71
FirmwareParams::pid_moving_buffer_size
int32_t pid_moving_buffer_size
Definition: motor_parameters.h:63
ros::NodeHandle


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