VehicleAckermann.h
Go to the documentation of this file.
00001 /*+-------------------------------------------------------------------------+
00002   |                       MultiVehicle simulator (libmvsim)                 |
00003   |                                                                         |
00004   | Copyright (C) 2014  Jose Luis Blanco Claraco (University of Almeria)    |
00005   | Copyright (C) 2017  Borys Tymchenko (Odessa Polytechnic University)     |
00006   | Distributed under GNU General Public License version 3                  |
00007   |   See <http://www.gnu.org/licenses/>                                    |
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         // Wheels: [0]:rear-left, [1]:rear-right, [2]: front-left, [3]: front-right
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);  // See base class docs
00091                 virtual void load_config(
00092                         const rapidxml::xml_node<char>& node);  // See base class docs
00093                 virtual void teleop_interface(
00094                         const TeleopInput& in, TeleopOutput& out);  // See base class docs
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);  // See base class docs
00111                 virtual void load_config(
00112                         const rapidxml::xml_node<char>& node);  // See base class docs
00113                 virtual void teleop_interface(
00114                         const TeleopInput& in, TeleopOutput& out);  // See base class docs
00115 
00116                 double KP, KI, KD;  
00117                 double max_torque;  
00118 
00119                 // See base docs.
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];  //<! [0]:fl, [1]: fr
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);  // See base class docs
00147                 virtual void load_config(
00148                         const rapidxml::xml_node<char>& node);  // See base class docs
00149                 virtual void teleop_interface(
00150                         const TeleopInput& in, TeleopOutput& out);  // See base class docs
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   // end controllers
00167 
00168         virtual vec3 getVelocityLocalOdoEstimate() const;  // See docs of base class
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         // See base class docs
00181         virtual void dynamics_load_params_from_xml(
00182                 const rapidxml::xml_node<char>* xml_node);
00183         // See base class doc
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 }


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 22:08:35