31 #include <dynamic_reconfigure/server.h> 34 #include <ubiquity_motor/PIDConfig.h> 38 #include <boost/thread.hpp> 42 static const double BILLION = 1000000000.0;
51 if (level == 0xFFFFFFFF) {
57 }
else if (level == 2) {
59 }
else if (level == 4) {
61 }
else if (level == 8) {
63 }
else if (level == 16) {
65 }
else if (level == 32) {
68 ROS_ERROR(
"Unsupported dynamic_reconfigure level %u", level);
72 int main(
int argc,
char* argv[]) {
82 std::unique_ptr<MotorHardware> robot =
nullptr;
86 while (
ros::ok() && robot.get() ==
nullptr) {
88 robot.reset(
new MotorHardware(nh, serial_params, firmware_params));
90 catch (
const serial::IOException& e) {
94 ctrlLoopDelay.
sleep();
104 dynamic_reconfigure::Server<ubiquity_motor::PIDConfig> server;
105 dynamic_reconfigure::Server<ubiquity_motor::PIDConfig>::CallbackType
f;
108 server.setCallback(f);
110 robot->setParams(firmware_params);
111 robot->requestFirmwareVersion();
114 ctrlLoopDelay.
sleep();
117 ROS_INFO(
"Request the firmware daycode");
118 robot->requestFirmwareDate();
123 robot->diag_updater.broadcast(0,
"Establishing communication with motors");
126 while (
ros::ok() && robot->firmware_version == 0) {
128 ROS_ERROR(
"The Firmware not reporting its version");
129 robot->requestFirmwareVersion();
131 ctrlLoopDelay.
sleep();
138 robot->requestFirmwareDate();
144 ROS_DEBUG(
"Firmware is version %d. Setting Controller board version to %d",
147 ROS_DEBUG(
"Controller board version has been set to %d",
149 ctrlLoopDelay.
sleep();
155 ctrlLoopDelay.
sleep();
157 ctrlLoopDelay.
sleep();
162 ctrlLoopDelay.
sleep();
164 ctrlLoopDelay.
sleep();
165 robot->setMaxPwm(firmware_params.
max_pwm);
166 ctrlLoopDelay.
sleep();
171 ctrlLoopDelay.
sleep();
178 for (
int i = 0; i < 5; i++) {
179 ctrlLoopDelay.
sleep();
183 float minCycleTime = 0.75 * expectedCycleTime;
184 float maxCycleTime = 1.25 * expectedCycleTime;
187 robot->clearCommands();
190 ROS_WARN(
"Starting motor control node now");
193 double estopReleaseDeadtime = 0.8;
194 double estopReleaseDelay = 0.0;
197 elapsed = current_time - last_time;
198 last_time = current_time;
200 float elapsedSecs = elapsed.
toSec();
201 if (minCycleTime < elapsedSecs && elapsedSecs < maxCycleTime) {
202 cm.update(current_time, elapsed);
205 ROS_WARN(
"Resetting controller due to time jump %f seconds",
208 robot->clearCommands();
210 robot->setParams(firmware_params);
214 if (robot->getEstopState()) {
215 robot->writeSpeedsInRadians(0.0, 0.0);
216 estopReleaseDelay = estopReleaseDeadtime;
218 if (estopReleaseDelay > 0.0) {
221 robot->writeSpeedsInRadians(0.0, 0.0);
223 robot->writeSpeeds();
227 robot->diag_updater.update();
228 ctrlLoopDelay.
sleep();
#define MIN_FW_FIRMWARE_DATE
double controller_loop_rate
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define MIN_FW_HW_VERSION_SET
int32_t pid_moving_buffer_size
#define MIN_FW_MAX_SPEED_AND_PWM
static FirmwareParams firmware_params
int32_t controller_board_version
int32_t estop_pid_threshold
#define MIN_FW_ESTOP_SUPPORT
void PID_update_callback(const ubiquity_motor::PIDConfig &config, uint32_t level)
static CommsParams serial_params
static NodeParams node_params
int main(int argc, char *argv[])
static const double BILLION
Duration expectedCycleTime() const