19 using namespace mvsim;
88 *xml_chassis, attribs, {},
89 "[DynamicsAckermannDrivetrain::dynamics_load_params_from_xml]");
97 "[DynamicsAckermannDrivetrain::dynamics_load_params_from_xml]");
104 const char* w_names[4] = {
111 for (
size_t i = 0; i < 4; i++)
122 double front_x = 1.3;
123 double front_d = 2.0;
126 ack_ps[
"f_wheels_x"] =
TParamEntry(
"%lf", &front_x);
127 ack_ps[
"f_wheels_d"] =
TParamEntry(
"%lf", &front_d);
132 *xml_node, ack_ps, {},
133 "[DynamicsAckermannDrivetrain::dynamics_load_params_from_xml]");
145 const char* drive_names[6] = {
"open_front",
"open_rear",
"open_4wd",
146 "torsen_front",
"torsen_rear",
"torsen_4wd"};
153 std::string diff_type;
157 *xml_drive, attribs, {},
158 "[DynamicsAckermannDrivetrain::dynamics_load_params_from_xml]");
160 for (
size_t i = 0; i < DifferentialType::DIFF_MAX; ++i)
162 if (diff_type == drive_names[i])
170 drive_params[
"front_rear_split"] =
173 drive_params[
"front_left_right_split"] =
175 drive_params[
"front_left_right_bias"] =
177 drive_params[
"rear_left_right_split"] =
179 drive_params[
"rear_left_right_bias"] =
183 *xml_drive, drive_params, {},
184 "[DynamicsAckermannDrivetrain::dynamics_load_params_from_xml]");
196 if (!control_class || !control_class->
value())
198 "[DynamicsAckermannDrivetrain] Missing 'class' attribute " 199 "in <controller> XML node");
201 const std::string sCtrlClass = std::string(control_class->
value());
213 "[DynamicsAckermannDrivetrain] Unknown 'class'='%s' in " 214 "<controller> XML node",
215 sCtrlClass.c_str()));
227 const TSimulContext& context, std::vector<double>& out_torque_per_wheel)
230 out_torque_per_wheel.assign(4, 0.0);
231 double torque_split_per_wheel[4] = {0.0};
248 torque_split_per_wheel[
WHEEL_RL] = 0.0;
249 torque_split_per_wheel[
WHEEL_RR] = 0.0;
254 torque_split_per_wheel[
WHEEL_FL] = 0.0;
255 torque_split_per_wheel[
WHEEL_FR] = 0.0;
275 torque_split_per_wheel[
WHEEL_RL] = 0.0;
276 torque_split_per_wheel[
WHEEL_RR] = 0.0;
288 torque_split_per_wheel[
WHEEL_FL] = 0.0;
289 torque_split_per_wheel[
WHEEL_FR] = 0.0;
305 const double w_F = w_FL + w_FR;
306 const double w_R = w_RL + w_RR;
326 torque_split_per_wheel[
WHEEL_FL] = t_F * t_FL;
327 torque_split_per_wheel[
WHEEL_FR] = t_F * t_FR;
328 torque_split_per_wheel[
WHEEL_RL] = t_R * t_RL;
329 torque_split_per_wheel[
WHEEL_RR] = t_R * t_RR;
337 "DynamicsAckermannDrivetrain::invoke_motor_controllers: \ 338 Unknown differential type!");
343 ASSERT_(out_torque_per_wheel.size() == 4);
344 for (
int i = 0; i < 4; i++)
346 out_torque_per_wheel[i] =
360 const double desired_equiv_steer_ang,
double& out_fl_ang,
361 double& out_fr_ang)
const 368 const double w_l = w / l;
372 const bool delta_neg = (desired_equiv_steer_ang < 0);
373 ASSERT_LT_(delta, 0.5 *
M_PI - 0.01);
374 const double cot_do = 1.0 / tan(delta) + 0.5 * w_l;
375 const double cot_di = cot_do - w_l;
378 (delta_neg ? out_fr_ang : out_fl_ang) =
379 atan(1.0 / cot_di) * (delta_neg ? -1.0 : 1.0);
380 (delta_neg ? out_fl_ang : out_fr_ang) =
381 atan(1.0 / cot_do) * (delta_neg ? -1.0 : 1.0);
385 const double w1,
const double w2,
const double diffBias,
386 const double splitRatio,
double& t1,
double& t2)
388 if (mrpt::signWithZero(w1) == 0.0 || mrpt::signWithZero(w2) == 0.0)
391 t2 = 1.0 - splitRatio;
395 const double w1Abs = std::abs(w1);
396 const double w2Abs = std::abs(w2);
397 const double omegaMax = std::max(w1Abs, w2Abs);
398 const double omegaMin = std::min(w1Abs, w2Abs);
400 const double delta = omegaMax - diffBias * omegaMin;
402 const double deltaTorque = (delta > 0) ? delta / omegaMax : 0.0
f;
403 const double f1 = (w1Abs - w2Abs > 0) ? splitRatio * (1.0
f - deltaTorque)
404 : splitRatio * (1.0f + deltaTorque);
405 const double f2 = (w1Abs - w2Abs > 0)
406 ? (1.0
f - splitRatio) * (1.0f + deltaTorque)
407 : (1.0
f - splitRatio) * (1.0f - deltaTorque);
408 const double denom = 1.0f / (f1 + f2);
432 "The two wheels of a differential vehicle CAN'T by at the same Y " 435 const double w_veh = (w1 * R1 - w0 * R0) / Ay;
440 odo_vel.
omega = w_veh;
mrpt::img::TColor m_chassis_color
This file contains rapidxml parser and DOM implementation.
void updateMaxRadiusFromPoly()
excludes the mass of wheels)
DifferentialType m_diff_type
min turning radius
std::map< std::string, TParamEntry > TParameterDefinitions
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
GLubyte GLubyte GLubyte GLubyte w
virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate() const override
static const char * class_name()
void parse_xmlnode_attribs(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions ¶ms, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="")
virtual void dynamics_load_params_from_xml(const rapidxml::xml_node< char > *xml_node) override
virtual void invoke_motor_controllers(const TSimulContext &context, std::vector< double > &out_force_per_wheel) override
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
DynamicsAckermannDrivetrain(World *parent)
void computeDiffTorqueSplit(const double w1, const double w2, const double diffBias, const double defaultSplitRatio, double &t1, double &t2)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
double DEG2RAD(const double x)
static const char * class_name()
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
static const char * class_name()
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
std::vector< Wheel > m_wheels_info
std::shared_ptr< ControllerBase > ControllerBasePtr
double steer_ang
Equivalent ackerman steering angle.
T b2Clamp(T a, T low, T high)
ControllerBasePtr m_controller
The installed controller.
std::vector< b2Fixture * > m_fixture_wheels
double m_chassis_z_min
each change via updateMaxRadiusFromPoly()
void parse_xmlnode_shape(const rapidxml::xml_node< char > &xml_node, mrpt::math::TPolygon2D &out_poly, const char *functionNameContext="")
mrpt::math::TPolygon2D m_chassis_poly
#define ASSERTMSG_(f, __ERROR_MSG)
b2Fixture * m_fixture_chassis
Created at.
void computeFrontWheelAngles(const double desired_equiv_steer_ang, double &out_fl_ang, double &out_fr_ang) const
const char_t & front(const std::string &s)
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble f