VehicleDifferential_ControllerTwistIdeal.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
11 
12 using namespace mvsim;
13 
16  : ControllerBase(veh)
17 {
18  // Get distance between wheels:
19  // Warning: the controller *assumes* that both wheels are parallel (as it's
20  // a rule in differential robots!!)
21  distWheels_ = veh_.wheels_info_[0].y - veh_.wheels_info_[1].y;
22  ASSERT_(distWheels_ > 0);
23 }
24 
26  [[maybe_unused]] const DynamicsDifferential::TControllerInput& ci,
28 {
29  co.wheel_torque_l = 0;
30  co.wheel_torque_r = 0;
31 }
32 
34  [[maybe_unused]] const TSimulContext& context)
35 {
36  // Fake controller: just set the setpoint as state and we are done.
37  const auto sp = setpoint();
38  this->veh_.setTwist(sp);
39 }
40 
42  const TeleopInput& in, TeleopOutput& out)
43 {
45 
46  auto lck = mrpt::lockHelper(setpointMtx_);
47 
48  switch (in.keycode)
49  {
50  case 'W':
51  case 'w':
52  setpoint_.vx += 0.1;
53  break;
54 
55  case 'S':
56  case 's':
57  setpoint_.vx -= 0.1;
58  break;
59 
60  case 'A':
61  case 'a':
62  setpoint_.omega += 2.0 * M_PI / 180;
63  break;
64 
65  case 'D':
66  case 'd':
67  setpoint_.omega -= 2.0 * M_PI / 180;
68  break;
69 
70  case ' ':
71  {
72  setpoint_ = {0, 0, 0};
73  }
74  break;
75  };
76  out.append_gui_lines += "[Controller=" + std::string(class_name()) +
77  "] Teleop keys:\n"
78  "w/s=forward/backward.\n"
79  "a/d=left/right.\n"
80  "spacebar=stop.\n";
81 
82  out.append_gui_lines += mrpt::format(
83  "setpoint: lin=%.03f ang=%.03f deg/s\n", setpoint_.vx,
84  180.0 / M_PI * setpoint_.omega);
85 }
#define M_PI
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out) override
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out) override
void control_step(const DynamicsDifferential::TControllerInput &ci, DynamicsDifferential::TControllerOutput &co) override
mrpt::math::TTwist2D setpoint_
"vx" and "omega" only


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21