simple_loop.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10  * Includes
11  ****************************************************************************/
12 
13 #include <csignal>
14 #include <ecl/time.hpp>
15 #include <ecl/sigslots.hpp>
16 #include <ecl/geometry/pose2d.hpp>
17 #include <ecl/linear_algebra.hpp>
18 #include "xbot_driver/xbot.hpp"
19 
20 /*****************************************************************************
21 ** Classes
22 *****************************************************************************/
23 
24 class XbotManager {
25 public:
27  dx(0.0), dth(0.0),
29  {
30  xbot::Parameters parameters;
31  parameters.sigslots_namespace = "/xbot";
32  parameters.base_port = "/dev/xbot";
33  parameters.enable_acceleration_limiter = false;
34  xbot.init(parameters);
35  xbot.enable();
36  slot_stream_data.connect("/xbot/stream_data");
37  }
38 
40  xbot.setBaseControl(0,0); // linear_velocity, angular_velocity in (m/s), (rad/s)
41  xbot.disable();
42  }
43 
45  ecl::Pose2D<double> pose_update;
46  ecl::linear_algebra::Vector3d pose_update_rates;
47  xbot.updateOdometry(pose_update, pose_update_rates);
48  pose *= pose_update;
49  dx += pose_update.x();
50  dth += pose_update.heading();
51  //std::cout << dx << ", " << dth << std::endl;
52  std::cout << xbot.getHeading() << ", " << pose.heading() << std::endl;
53  //std::cout << "[" << pose.x() << ", " << pose.y() << ", " << pose.heading() << "]" << std::endl;
54  processMotion();
55  }
56 
57  // Generate square motion
58  void processMotion() {
59 // if (dx >= 1.0 && dth >= ecl::pi/2.0) { dx=0.0; dth=0.0; xbot.setBaseControl(0.0, 0.0); return; }
60 // else if (dx >= 1.0) { xbot.setBaseControl(0.0, 10.3); return; }
61 // else { xbot.setBaseControl(0.4, 0.0); return; }
62  xbot.setBaseControl(0.0, -1.1);
63 // xbot.setLiftControl(0);
64 // xbot.setPlatformCameraControl(10,20);
65 // xbot.resetXbot();
66  return;
67  }
68 
70  return pose;
71  }
72 
73 private:
74  double dx, dth;
78 };
79 
80 /*****************************************************************************
81 ** Signal Handler
82 *****************************************************************************/
83 
84 bool shutdown_req = false;
85 void signalHandler(int signum) {
86  shutdown_req = true;
87 }
88 
89 /*****************************************************************************
90 ** Main
91 *****************************************************************************/
92 
93 int main(int argc, char** argv)
94 {
95  signal(SIGINT, signalHandler);
96 
97  std::cout << "Demo : Example of simple control loop." << std::endl;
98  XbotManager xbot_manager;
99 
100 
101 
102  ecl::Sleep sleep(1);
104  try {
105  while (!shutdown_req){
106  sleep();
107  pose = xbot_manager.getPose();
108 // std::cout << "current pose: [" << pose.x() << ", " << pose.y() << ", " << pose.heading() << "]" << std::endl;
109  }
110  } catch ( ecl::StandardException &e ) {
111  std::cout << e.what();
112  }
113  return 0;
114 }
std::string base_port
The serial device port name [/dev/xbot].
Definition: parameters.hpp:51
const char * what() const
Parameter list and validator for the xbot.
Definition: parameters.hpp:35
std::string sigslots_namespace
The first part of a sigslot connection namespace ["/xbot"].
Definition: parameters.hpp:53
xbot::Xbot xbot
ecl::Pose2D< double > pose
Definition: simple_loop.cpp:75
int main(int argc, char **argv)
Definition: simple_loop.cpp:93
EndOfLine endl
Device driver core interface.
Standard exception type, provides code location and error string.
Keyboard remote control for our robot core (mobile base).
ecl::Slot slot_stream_data
Definition: sigslots.cpp:53
void processStreamData()
Definition: sigslots.cpp:46
void processMotion()
Definition: simple_loop.cpp:58
bool shutdown_req
Definition: simple_loop.cpp:84
void connect(const std::string &topic)
ecl::Pose2D< double > getPose()
Definition: simple_loop.cpp:69
void signalHandler(int signum)
Definition: simple_loop.cpp:85
Definition: command.hpp:30
bool enable_acceleration_limiter
Enable or disable the acceleration limiter [true].
Definition: parameters.hpp:55
Function loading component of a callback system.
Definition: slot.hpp:48
The core xbot driver class.
Definition: xbot.hpp:86


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:38