Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #pragma once
00011
00012 #include <mvsim/VehicleBase.h>
00013 #include <mvsim/PID_Controller.h>
00014
00015 #include <mrpt/opengl/CSetOfObjects.h>
00016 #include <mrpt/math/lightweight_geom_data.h>
00017 #if MRPT_VERSION<0x199
00018 #include <mrpt/utils/TColor.h>
00019 using mrpt::utils::TColor;
00020 using mrpt::utils::DEG2RAD;
00021 using mrpt::utils::keep_min;
00022 using mrpt::utils::keep_max;
00023 #else
00024 #include <mrpt/img/TColor.h>
00025 using mrpt::img::TColor;
00026 using mrpt::DEG2RAD;
00027 using mrpt::keep_min;
00028 using mrpt::keep_max;
00029 #endif
00030
00031 namespace mvsim
00032 {
00036 class DynamicsAckermann : public VehicleBase
00037 {
00038 DECLARES_REGISTER_VEHICLE_DYNAMICS(DynamicsAckermann)
00039 public:
00040
00041 enum
00042 {
00043 WHEEL_RL = 0,
00044 WHEEL_RR = 1,
00045 WHEEL_FL = 2,
00046 WHEEL_FR = 3
00047 };
00048
00049 DynamicsAckermann(World* parent);
00050
00052 double getMaxSteeringAngle() const { return m_max_steer_ang; }
00053 void setMaxSteeringAngle(double val) { m_max_steer_ang = val; }
00057 struct TControllerInput
00058 {
00059 TSimulContext context;
00060 };
00061 struct TControllerOutput
00062 {
00063 double fl_torque, fr_torque, rl_torque, rr_torque;
00064 double steer_ang;
00065 TControllerOutput()
00066 : fl_torque(0),
00067 fr_torque(0),
00068 rl_torque(0),
00069 rr_torque(0),
00070 steer_ang(0)
00071 {
00072 }
00073 };
00074
00076 typedef ControllerBaseTempl<DynamicsAckermann> ControllerBase;
00077 typedef std::shared_ptr<ControllerBase> ControllerBasePtr;
00078
00079 class ControllerRawForces : public ControllerBase
00080 {
00081 public:
00082 ControllerRawForces(DynamicsAckermann& veh);
00083 static const char* class_name() { return "raw"; }
00086 double setpoint_wheel_torque_l, setpoint_wheel_torque_r,
00087 setpoint_steer_ang;
00088 virtual void control_step(
00089 const DynamicsAckermann::TControllerInput& ci,
00090 DynamicsAckermann::TControllerOutput& co);
00091 virtual void load_config(
00092 const rapidxml::xml_node<char>& node);
00093 virtual void teleop_interface(
00094 const TeleopInput& in, TeleopOutput& out);
00095 };
00096
00099 class ControllerTwistFrontSteerPID : public ControllerBase
00100 {
00101 public:
00102 ControllerTwistFrontSteerPID(DynamicsAckermann& veh);
00103 static const char* class_name() { return "twist_front_steer_pid"; }
00106 double setpoint_lin_speed,
00107 setpoint_ang_speed;
00108 virtual void control_step(
00109 const DynamicsAckermann::TControllerInput& ci,
00110 DynamicsAckermann::TControllerOutput& co);
00111 virtual void load_config(
00112 const rapidxml::xml_node<char>& node);
00113 virtual void teleop_interface(
00114 const TeleopInput& in, TeleopOutput& out);
00115
00116 double KP, KI, KD;
00117 double max_torque;
00118
00119
00120 virtual bool setTwistCommand(const double vx, const double wz)
00121 {
00122 setpoint_lin_speed = vx;
00123 setpoint_ang_speed = wz;
00124 return true;
00125 }
00126
00127 private:
00128 double m_dist_fWheels, m_r2f_L;
00129 PID_Controller m_PID[2];
00130 };
00131
00134 class ControllerFrontSteerPID : public ControllerBase
00135 {
00136 public:
00137 ControllerFrontSteerPID(DynamicsAckermann& veh);
00138 static const char* class_name() { return "front_steer_pid"; }
00141 double setpoint_lin_speed, setpoint_steer_ang;
00142
00143
00144 virtual void control_step(
00145 const DynamicsAckermann::TControllerInput& ci,
00146 DynamicsAckermann::TControllerOutput& co);
00147 virtual void load_config(
00148 const rapidxml::xml_node<char>& node);
00149 virtual void teleop_interface(
00150 const TeleopInput& in, TeleopOutput& out);
00151
00152 double KP, KI, KD;
00153 double max_torque;
00154 private:
00155 ControllerTwistFrontSteerPID m_twist_control;
00156 double m_r2f_L;
00157 };
00158
00159 const ControllerBasePtr& getController() const { return m_controller; }
00160 ControllerBasePtr& getController() { return m_controller; }
00161 virtual ControllerBaseInterface* getControllerInterface()
00162 {
00163 return m_controller.get();
00164 }
00165
00167
00168 virtual vec3 getVelocityLocalOdoEstimate() const;
00169
00175 void computeFrontWheelAngles(
00176 const double desired_equiv_steer_ang, double& out_fl_ang,
00177 double& out_fr_ang) const;
00178
00179 protected:
00180
00181 virtual void dynamics_load_params_from_xml(
00182 const rapidxml::xml_node<char>* xml_node);
00183
00184 virtual void invoke_motor_controllers(
00185 const TSimulContext& context, std::vector<double>& out_force_per_wheel);
00186
00187 private:
00188 ControllerBasePtr m_controller;
00189
00190 double m_max_steer_ang;
00191
00192 };
00193 }