15 #include <mrpt/opengl/COpenGLScene.h> 19 using namespace mvsim;
25 m_max_steer_ang(DEG2RAD(30))
29 m_chassis_mass = 500.0;
30 m_chassis_z_min = 0.20;
31 m_chassis_z_max = 1.40;
32 m_chassis_color = TColor(0xe8, 0x30, 0x00);
35 m_chassis_poly.clear();
36 m_chassis_poly.push_back(TPoint2D(-0.8, -1.0));
37 m_chassis_poly.push_back(TPoint2D(-0.8, 1.0));
38 m_chassis_poly.push_back(TPoint2D(1.5, 0.9));
39 m_chassis_poly.push_back(TPoint2D(1.8, 0.8));
40 m_chassis_poly.push_back(TPoint2D(1.8, -0.8));
41 m_chassis_poly.push_back(TPoint2D(1.5, -0.9));
42 updateMaxRadiusFromPoly();
44 m_fixture_chassis = NULL;
45 for (
int i = 0; i < 4; i++) m_fixture_wheels[i] = NULL;
72 std::map<std::string, TParamEntry> attribs;
73 attribs[
"mass"] =
TParamEntry(
"%lf", &this->m_chassis_mass);
74 attribs[
"zmin"] =
TParamEntry(
"%lf", &this->m_chassis_z_min);
75 attribs[
"zmax"] =
TParamEntry(
"%lf", &this->m_chassis_z_max);
76 attribs[
"color"] =
TParamEntry(
"%color", &this->m_chassis_color);
79 *xml_chassis, attribs,
80 "[DynamicsAckermann::dynamics_load_params_from_xml]");
87 *xml_shape, m_chassis_poly,
88 "[DynamicsAckermann::dynamics_load_params_from_xml]");
95 const char* w_names[4] = {
102 for (
size_t i = 0; i < 4; i++)
106 if (xml_wheel) m_wheels_info[i].loadFromXML(xml_wheel);
113 double front_x = 1.3;
114 double front_d = 2.0;
115 std::map<std::string, TParamEntry> ack_ps;
117 ack_ps[
"f_wheels_x"] =
TParamEntry(
"%lf", &front_x);
118 ack_ps[
"f_wheels_d"] =
TParamEntry(
"%lf", &front_d);
124 "[DynamicsAckermann::dynamics_load_params_from_xml]");
127 m_wheels_info[
WHEEL_FL].x = front_x;
128 m_wheels_info[
WHEEL_FL].y = 0.5 * front_d;
130 m_wheels_info[
WHEEL_FR].x = front_x;
131 m_wheels_info[
WHEEL_FR].y = -0.5 * front_d;
143 if (!control_class || !control_class->
value())
145 "[DynamicsAckermann] Missing 'class' attribute in " 146 "<controller> XML node");
148 const std::string sCtrlClass = std::string(control_class->
value());
161 "[DynamicsAckermann] Unknown 'class'='%s' in " 162 "<controller> XML node",
163 sCtrlClass.c_str()));
175 const TSimulContext& context, std::vector<double>& out_torque_per_wheel)
178 out_torque_per_wheel.assign(4, 0.0);
203 const double desired_equiv_steer_ang,
double& out_fl_ang,
204 double& out_fr_ang)
const 211 const double w_l = w / l;
215 const bool delta_neg = (desired_equiv_steer_ang < 0);
216 ASSERT_BELOW_(delta, 0.5 * M_PI - 0.01);
217 const double cot_do = 1.0 / tan(delta) + 0.5 * w_l;
218 const double cot_di = cot_do - w_l;
221 (delta_neg ? out_fr_ang : out_fl_ang) =
222 atan(1.0 / cot_di) * (delta_neg ? -1.0 : 1.0);
223 (delta_neg ? out_fl_ang : out_fr_ang) =
224 atan(1.0 / cot_do) * (delta_neg ? -1.0 : 1.0);
236 const double w0 = m_wheels_info[
WHEEL_RL].getW();
237 const double w1 = m_wheels_info[
WHEEL_RR].getW();
238 const double R0 = m_wheels_info[
WHEEL_RL].diameter * 0.5;
239 const double R1 = m_wheels_info[
WHEEL_RR].diameter * 0.5;
244 "The two wheels of a differential vehicle CAN'T by at the same Y " 247 const double w_veh = (w1 * R1 - w0 * R0) / Ay;
248 const double vx_veh = w0 * R0 + w_veh * m_wheels_info[
WHEEL_RL].y;
250 odo_vel.
vals[0] = vx_veh;
251 odo_vel.
vals[2] = w_veh;
254 odo_vel.
vals[1] = 0.0;
259 printf(
"\n gt: vx=%7.03f, vy=%7.03f, w= %7.03fdeg\n", gt_vel.
vals[0], gt_vel.
vals[1], mrpt::utils::RAD2DEG(gt_vel.
vals[2]));
260 printf(
"odo: vx=%7.03f, vy=%7.03f, w= %7.03fdeg\n", odo_vel.
vals[0], odo_vel.
vals[1], mrpt::utils::RAD2DEG(odo_vel.
vals[2]));
This file contains rapidxml parser and DOM implementation.
void parse_xmlnode_shape(const rapidxml::xml_node< char > &xml_node, mrpt::math::TPolygon2D &out_poly, const char *function_name_context="")
DynamicsAckermann(World *parent)
ControllerBasePtr m_controller
The installed controller.
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > ¶ms, const char *function_name_context="")
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > ¶ms, const char *function_name_context="")
virtual void dynamics_load_params_from_xml(const rapidxml::xml_node< char > *xml_node)
virtual vec3 getVelocityLocalOdoEstimate() const
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
void computeFrontWheelAngles(const double desired_equiv_steer_ang, double &out_fl_ang, double &out_fr_ang) const
TFSIMD_FORCE_INLINE const tfScalar & w() const
std::shared_ptr< ControllerBase > ControllerBasePtr
T b2Clamp(T a, T low, T high)
double steer_ang
Equivalent ackerman steering angle.
static const char * class_name()
vec3 getVelocityLocal() const
virtual void invoke_motor_controllers(const TSimulContext &context, std::vector< double > &out_force_per_wheel)
static const char * class_name()
static const char * class_name()