horizon_legacy_wrapper.cpp
Go to the documentation of this file.
00001 
00032 #include "husky_base/horizon_legacy/clearpath.h"
00033 #include <ros/ros.h>
00034 
00035 namespace
00036 {
00037   std::string port_;
00038 }
00039 
00040 namespace horizon_legacy
00041 {
00042 
00043   void reconnect()
00044   {
00045     if (port_.empty())
00046     {
00047       throw std::logic_error("Can't reconnect when port is not configured");
00048     }
00049     ROS_INFO_STREAM("Connecting to Husky on port " << port_ << "...");
00050     clearpath::Transport::instance().configure(port_.c_str(), 3);
00051     ROS_INFO("Connected");
00052   }
00053 
00054   void connect(std::string port)
00055   {
00056     port_ = port;
00057     reconnect();
00058   }
00059 
00060   void configureLimits(double max_speed, double max_accel)
00061   {
00062 
00063     bool success = false;
00064     while (!success)
00065     {
00066       try
00067       {
00068         clearpath::SetMaxAccel(max_accel, max_accel).send();
00069         clearpath::SetMaxSpeed(max_speed, max_speed).send();
00070         success = true;
00071       }
00072       catch (clearpath::Exception *ex)
00073       {
00074         ROS_ERROR_STREAM("Error configuring velocity and accel limits: " << ex->message);
00075         reconnect();
00076       }
00077     }
00078   }
00079 
00080   void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
00081   {
00082     bool success = false;
00083     while (!success)
00084     {
00085       try
00086       {
00087         clearpath::SetDifferentialSpeed(speed_left, speed_right, accel_left, accel_right).send();
00088         success = true;
00089       }
00090       catch (clearpath::Exception *ex)
00091       {
00092         ROS_ERROR_STREAM("Error sending speed and accel command: " << ex->message);
00093         reconnect();
00094       }
00095     }
00096   }
00097 
00098 }


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Sat Jun 8 2019 18:26:01