core_wrapper.cpp
Go to the documentation of this file.
1 
32 #include "roch_base/core/sawyer.h"
33 #include <ros/ros.h>
34 
35 namespace
36 {
37  std::string port_;
38 }
39 
40 namespace core
41 {
42 
43  void reconnect()
44  {
45  if (port_.empty())
46  {
47  throw std::logic_error("Can't reconnect when port is not configured");
48  }
49  ROS_INFO_STREAM("Connecting to roch on port " << port_ << "...");
50  sawyer::Transport::instance().configure(port_.c_str(), 3);
51  }
52 
53  void connect(std::string port)
54  {
55  port_ = port;
56  reconnect();
57  }
58 
59  void configureLimits(double max_speed, double max_accel)
60  {
61 
62  bool success = false;
63  while (!success)
64  {
65  try
66  {
67 
68  sawyer::SetMaxAccel(max_accel, max_accel).send();
69  sawyer::SetMaxSpeed(max_speed, max_speed).send();
70  success = true;
71  }
72  catch (sawyer::Exception *ex)
73  {
74  ROS_ERROR_STREAM("Error configuring velocity and accel limits: " << ex->message);
75  reconnect();
76  }
77  }
78  }
79 
80  void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
81  {
82  bool success = false;
83  while (!success)
84  {
85  try
86  {
87  sawyer::SetDifferentialSpeed(speed_left, speed_right, accel_left, accel_right).send();
88  success = true;
89  }
90  catch (sawyer::Exception *ex)
91  {
92  ROS_ERROR_STREAM("Error sending speed and accel command: " << ex->message);
93  reconnect();
94  }
95  }
96  }
97  void controloverallSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
98  {
99  bool success = false;
100  double lin_vel = (speed_left + speed_right)*0.5;
101  double ang_vel = (speed_left - speed_right)/(2*0.12);
102 
103  double acc = (accel_left + accel_right)*0.5;
104 
105  while (!success)
106  {
107  try
108  {
109  sawyer::SetVelocity(lin_vel,ang_vel,acc).send();
110  success = true;
111  }
112  catch (sawyer::Exception *ex)
113  {
114  ROS_ERROR_STREAM("Error sending velocity setpt command: " << ex->message);
115  reconnect();
116  }
117  }
118  }
119 
120 }
static Transport & instance()
Definition: Transport.cpp:129
void reconnect()
const char * message
Definition: Exception.h:49
void connect(std::string port)
void controloverallSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
#define ROS_INFO_STREAM(args)
void configureLimits(double max_speed, double max_accel)
void configure(const char *device, int retries)
Definition: Transport.cpp:164
#define ROS_ERROR_STREAM(args)


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:13