Vehicleackermann_Drivetrain_ControllerTwistFrontSteerPID.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 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 #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().vx;
57  const double vel_des = setpoint_lin_speed;
58 
59  // "-" because \tau<0 makes robot moves forwards.
60  co.drive_torque = -m_PID.compute(vel_des - vel_act, ci.context.dt);
61 }
62 
64  const rapidxml::xml_node<char>& node)
65 {
67  params["KP"] = TParamEntry("%lf", &KP);
68  params["KI"] = TParamEntry("%lf", &KI);
69  params["KD"] = TParamEntry("%lf", &KD);
70  params["max_torque"] = TParamEntry("%lf", &max_torque);
71 
72  // Initial speed.
73  params["V"] = TParamEntry("%lf", &this->setpoint_lin_speed);
74  params["W"] = TParamEntry("%lf_deg", &this->setpoint_ang_speed);
75 
76  parse_xmlnode_children_as_param(node, params);
77 }
78 
81 {
83 
84  switch (in.keycode)
85  {
86  case 'W':
87  case 'w':
88  setpoint_lin_speed += 0.1;
89  break;
90 
91  case 'S':
92  case 's':
93  setpoint_lin_speed -= 0.1;
94  break;
95 
96  case 'A':
97  case 'a':
98  setpoint_ang_speed += 1.0 * M_PI / 180.0;
99  break;
100 
101  case 'D':
102  case 'd':
103  setpoint_ang_speed -= 1.0 * M_PI / 180.0;
104  break;
105 
106  case ' ':
107  setpoint_lin_speed = .0;
108  setpoint_ang_speed = .0;
109  break;
110  };
111  out.append_gui_lines += "[Controller=" + string(class_name()) +
112  "] Teleop keys: w/s=incr/decr lin speed. "
113  "a/d=left/right steering. spacebar=stop.\n";
115  "setpoint: v=%.03f w=%.03f deg/s\n", setpoint_lin_speed,
116  setpoint_ang_speed * 180.0 / M_PI);
117 }
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions &params, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
Definition: xml_utils.cpp:179
#define M_PI
double max_torque
Maximum abs. value torque (for clamp) [Nm].
GLuint in
double dt
timestep
Definition: basic_types.h:61
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out) override
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
GLsizei const GLcharARB ** string
double steer_ang
Equivalent ackerman steering angle.
double max_out
For clamping (0=no clamp)
double compute(double err, double dt)
#define ASSERT_(f)
GLfloat * params
virtual void control_step(const DynamicsAckermannDrivetrain::TControllerInput &ci, DynamicsAckermannDrivetrain::TControllerOutput &co) override
const float R


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51