Go to the documentation of this file.00001
00032 #include "roch_base/core/sawyer.h"
00033 #include <ros/ros.h>
00034
00035 namespace
00036 {
00037 std::string port_;
00038 }
00039
00040 namespace core
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 roch on port " << port_ << "...");
00050 sawyer::Transport::instance().configure(port_.c_str(), 3);
00051 }
00052
00053 void connect(std::string port)
00054 {
00055 port_ = port;
00056 reconnect();
00057 }
00058
00059 void configureLimits(double max_speed, double max_accel)
00060 {
00061
00062 bool success = false;
00063 while (!success)
00064 {
00065 try
00066 {
00067
00068 sawyer::SetMaxAccel(max_accel, max_accel).send();
00069 sawyer::SetMaxSpeed(max_speed, max_speed).send();
00070 success = true;
00071 }
00072 catch (sawyer::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 sawyer::SetDifferentialSpeed(speed_left, speed_right, accel_left, accel_right).send();
00088 success = true;
00089 }
00090 catch (sawyer::Exception *ex)
00091 {
00092 ROS_ERROR_STREAM("Error sending speed and accel command: " << ex->message);
00093 reconnect();
00094 }
00095 }
00096 }
00097 void controloverallSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
00098 {
00099 bool success = false;
00100 double lin_vel = (speed_left + speed_right)*0.5;
00101 double ang_vel = (speed_left - speed_right)/(2*0.12);
00102
00103 double acc = (accel_left + accel_right)*0.5;
00104
00105 while (!success)
00106 {
00107 try
00108 {
00109 sawyer::SetVelocity(lin_vel,ang_vel,acc).send();
00110 success = true;
00111 }
00112 catch (sawyer::Exception *ex)
00113 {
00114 ROS_ERROR_STREAM("Error sending velocity setpt command: " << ex->message);
00115 reconnect();
00116 }
00117 }
00118 }
00119
00120 }