Vehicleackermann_Drivetrain_ControllerTwistFrontSteerPID.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
11 #include "xml_utils.h"
12 
13 using namespace mvsim;
14 using namespace std;
15 
18  : ControllerBase(veh),
19  setpoint_lin_speed(0),
20  setpoint_ang_speed(0),
21  KP(100),
22  KI(0),
23  KD(0),
24  max_torque(400.0)
25 {
26  // Get distance between wheels:
28  m_veh.m_wheels_info[WHEEL_FL].y - m_veh.m_wheels_info[WHEEL_FR].y;
29  m_r2f_L = m_veh.m_wheels_info[WHEEL_FL].x - m_veh.m_wheels_info[WHEEL_RL].x;
30 
31  ASSERT_(m_dist_fWheels > 0.0);
32  ASSERT_(m_r2f_L > 0.0);
33 }
34 
38 {
39  // 1st: desired steering angle:
40  // --------------------------------
41  if (setpoint_ang_speed == 0)
42  {
43  co.steer_ang = 0.0;
44  }
45  else
46  {
47  const double R = setpoint_lin_speed / setpoint_ang_speed;
48  co.steer_ang = atan(m_r2f_L / R);
49  }
50 
51  m_PID.KP = KP;
52  m_PID.KI = KI;
53  m_PID.KD = KD;
55 
56  const double vel_act = m_veh.getVelocityLocalOdoEstimate().vals[0];
57  const double vel_des = setpoint_lin_speed;
58 
60  vel_des - vel_act,
61  ci.context.dt); // "-" because \tau<0 makes robot moves forwards.
62 }
63 
65  const rapidxml::xml_node<char>& node)
66 {
67  std::map<std::string, TParamEntry> params;
68  params["KP"] = TParamEntry("%lf", &KP);
69  params["KI"] = TParamEntry("%lf", &KI);
70  params["KD"] = TParamEntry("%lf", &KD);
71  params["max_torque"] = TParamEntry("%lf", &max_torque);
72 
73  // Initial speed.
74  params["V"] = TParamEntry("%lf", &this->setpoint_lin_speed);
75  params["W"] = TParamEntry("%lf_deg", &this->setpoint_ang_speed);
76 
77  parse_xmlnode_children_as_param(node, params);
78 }
79 
82 {
84 
85  switch (in.keycode)
86  {
87  case 'W':
88  case 'w':
89  setpoint_lin_speed += 0.1;
90  break;
91 
92  case 'S':
93  case 's':
94  setpoint_lin_speed -= 0.1;
95  break;
96 
97  case 'A':
98  case 'a':
99  setpoint_ang_speed += 1.0 * M_PI / 180.0;
100  break;
101 
102  case 'D':
103  case 'd':
104  setpoint_ang_speed -= 1.0 * M_PI / 180.0;
105  break;
106 
107  case ' ':
108  setpoint_lin_speed = .0;
109  setpoint_ang_speed = .0;
110  break;
111  };
112  out.append_gui_lines += "[Controller=" + string(class_name()) +
113  "] Teleop keys: w/s=incr/decr lin speed. "
114  "a/d=left/right steering. spacebar=stop.\n";
115  out.append_gui_lines += mrpt::format(
116  "setpoint: v=%.03f w=%.03f deg/s\n", setpoint_lin_speed,
117  setpoint_ang_speed * 180.0 / M_PI);
118 }
double max_torque
Maximum abs. value torque (for clamp) [Nm].
double dt
timestep
Definition: basic_types.h:57
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out) override
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > &params, const char *function_name_context="")
Definition: xml_utils.cpp:196
double steer_ang
Equivalent ackerman steering angle.
double max_out
For clamping (0=no clamp)
double compute(double err, double dt)
virtual void control_step(const DynamicsAckermannDrivetrain::TControllerInput &ci, DynamicsAckermannDrivetrain::TControllerOutput &co)


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40