VehicleAckermann_Drivetrain.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 #include <mrpt/utils/TColor.h>
00018 
00019 namespace mvsim
00020 {
00029 class DynamicsAckermannDrivetrain : public VehicleBase
00030 {
00031         DECLARES_REGISTER_VEHICLE_DYNAMICS(DynamicsAckermannDrivetrain)
00032    public:
00033         // Wheels: [0]:rear-left, [1]:rear-right, [2]: front-left, [3]: front-right
00034         enum
00035         {
00036                 WHEEL_RL = 0,
00037                 WHEEL_RR = 1,
00038                 WHEEL_FL = 2,
00039                 WHEEL_FR = 3
00040         };
00041 
00042         enum DifferentialType
00043         {
00044                 DIFF_OPEN_FRONT = 0,
00045                 DIFF_OPEN_REAR = 1,
00046                 DIFF_OPEN_4WD = 2,
00047 
00048                 DIFF_TORSEN_FRONT = 3,
00049                 DIFF_TORSEN_REAR = 4,
00050                 DIFF_TORSEN_4WD = 5,
00051 
00052                 DIFF_MAX
00053         };
00054 
00055         DynamicsAckermannDrivetrain(World* parent);
00056 
00058         double getMaxSteeringAngle() const { return m_max_steer_ang; }
00059         void setMaxSteeringAngle(double val) { m_max_steer_ang = val; }
00063         struct TControllerInput
00064         {
00065                 TSimulContext context;
00066         };
00067         struct TControllerOutput
00068         {
00069                 double drive_torque;
00070                 double steer_ang;  
00071                 TControllerOutput() : drive_torque(0), steer_ang(0) {}
00072         };
00073 
00076         typedef ControllerBaseTempl<DynamicsAckermannDrivetrain> ControllerBase;
00077         typedef std::shared_ptr<ControllerBase> ControllerBasePtr;
00078 
00079         class ControllerRawForces : public ControllerBase
00080         {
00081            public:
00082                 ControllerRawForces(DynamicsAckermannDrivetrain& veh);
00083                 static const char* class_name() { return "raw"; }
00086                 double setpoint_wheel_torque, setpoint_steer_ang;
00087                 virtual void control_step(
00088                         const DynamicsAckermannDrivetrain::TControllerInput& ci,
00089                         DynamicsAckermannDrivetrain::TControllerOutput&
00090                                 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(DynamicsAckermannDrivetrain& 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 DynamicsAckermannDrivetrain::TControllerInput& ci,
00110                         DynamicsAckermannDrivetrain::TControllerOutput& co);
00111                 virtual void load_config(const rapidxml::xml_node<char>& node);
00112                 virtual void teleop_interface(const TeleopInput& in, TeleopOutput& out);
00113 
00114                 double KP, KI, KD;  
00115                 double max_torque;  
00116 
00117                 // See base docs.
00118                 virtual bool setTwistCommand(const double vx, const double wz)
00119                 {
00120                         setpoint_lin_speed = vx;
00121                         setpoint_ang_speed = wz;
00122                         return true;
00123                 }
00124 
00125            private:
00126                 double m_dist_fWheels, m_r2f_L;
00127                 PID_Controller m_PID;
00128         };
00129 
00130         class ControllerFrontSteerPID : public ControllerBase
00131         {
00132            public:
00133                 ControllerFrontSteerPID(DynamicsAckermannDrivetrain& veh);
00134                 static const char* class_name() { return "front_steer_pid"; }
00137                 double setpoint_lin_speed, setpoint_steer_ang;  
00138 
00139 
00140                 virtual void control_step(
00141                         const DynamicsAckermannDrivetrain::TControllerInput& ci,
00142                         DynamicsAckermannDrivetrain::TControllerOutput&
00143                                 co);  // See base class docs
00144                 virtual void load_config(
00145                         const rapidxml::xml_node<char>& node);  // See base class docs
00146                 virtual void teleop_interface(
00147                         const TeleopInput& in, TeleopOutput& out);  // See base class docs
00148 
00149                 double KP, KI, KD;  
00150                 double max_torque;  
00151            private:
00152                 ControllerTwistFrontSteerPID m_twist_control;
00153                 double m_r2f_L;
00154         };
00155 
00156         const ControllerBasePtr& getController() const { return m_controller; }
00157         ControllerBasePtr& getController() { return m_controller; }
00158         virtual ControllerBaseInterface* getControllerInterface()
00159         {
00160                 return m_controller.get();
00161         }
00162   // end controllers
00164 
00165         virtual vec3 getVelocityLocalOdoEstimate() const;  // See docs of base class
00166 
00172         void computeFrontWheelAngles(
00173                 const double desired_equiv_steer_ang, double& out_fl_ang,
00174                 double& out_fr_ang) const;
00175 
00178         void computeDiffTorqueSplit(
00179                 const double w1, const double w2, const double diffBias,
00180                 const double defaultSplitRatio, double& t1, double& t2);
00181 
00182    protected:
00183         // See base class docs
00184         virtual void dynamics_load_params_from_xml(
00185                 const rapidxml::xml_node<char>* xml_node);
00186         // See base class doc
00187         virtual void invoke_motor_controllers(
00188                 const TSimulContext& context, std::vector<double>& out_force_per_wheel);
00189 
00190    private:
00191         ControllerBasePtr m_controller;  
00192 
00193         double m_max_steer_ang;  
00194 
00195 
00196         DifferentialType m_diff_type;
00197 
00198         double m_FrontRearSplit;
00199         double m_FrontLRSplit;
00200         double m_RearLRSplit;
00201 
00202         double m_FrontRearBias;
00203         double m_FrontLRBias;
00204         double m_RearLRBias;
00205 };
00206 }


mvsim
Author(s):
autogenerated on Thu Sep 7 2017 09:27:48