horizon_legacy_wrapper.cpp
Go to the documentation of this file.
1 
33 #include <ros/ros.h>
34 
35 namespace
36 {
37  std::string port_;
38 }
39 
40 namespace horizon_legacy
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 Husky on port " << port_ << "...");
50  clearpath::Transport::instance().configure(port_.c_str(), 3);
51  ROS_INFO("Connected");
52  }
53 
54  void connect(std::string port)
55  {
56  port_ = port;
57  reconnect();
58  }
59 
60  void configureLimits(double max_speed, double max_accel)
61  {
62 
63  bool success = false;
64  while (!success)
65  {
66  try
67  {
68  clearpath::SetMaxAccel(max_accel, max_accel).send();
69  clearpath::SetMaxSpeed(max_speed, max_speed).send();
70  success = true;
71  }
72  catch (clearpath::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  clearpath::SetDifferentialSpeed(speed_left, speed_right, accel_left, accel_right).send();
88  success = true;
89  }
90  catch (clearpath::Exception *ex)
91  {
92  ROS_ERROR_STREAM("Error sending speed and accel command: " << ex->message);
93  reconnect();
94  }
95  }
96  }
97 
98 }
static Transport & instance()
Definition: Transport.cpp:129
void connect(std::string port)
const char * message
Definition: Exception.h:58
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
void configureLimits(double max_speed, double max_accel)
#define ROS_ERROR_STREAM(args)
void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
void configure(const char *device, int retries)
Definition: Transport.cpp:164


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Fri Oct 2 2020 03:40:07