Basic suspensions example (demo_IRR_suspension.cpp)

Simulate a simplified vehicle with double-wishbone suspensions (like racing cars) and drive it using the mouse over some sliders in the interface.

This tutorial shows how to:

• use the ChLinkDistance to represent massless rods, saving computational efforts.
• change the friction coefficient depending on the contact zone (here, half of the ground plane has lower friction).
• use the Irrlicht interface system to interact with a model.
• use ChLinkSpring to make spring-dampers
// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
//
// =============================================================================
// Authors: Alessandro Tasora
// =============================================================================
//
// - modeling a complex mechanism (a quarter car model)
// - using the ChLinkTSDA to make spring-damper system
// - using the ChLinkDistance class to represent long and thin massless rods,
// whose mass is negligible for dynamical analysis (as often happens in
// mechanisms) so they can be modeled as 'distance' constraints instead of
// making a thin body with small mass and two spherical joints at the end
// (wihch would be much less efficient from the computational point of view).
//
// =============================================================================
#include "chrono/core/ChRealtimeStep.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/physics/ChSystemNSC.h"
#include "chrono_irrlicht/ChIrrApp.h"
// Use the namespaces of Chrono
using namespace chrono;
using namespace chrono::irrlicht;
// Use the main namespaces of Irrlicht
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::io;
using namespace irr::gui;
// First of all, define a class for the 'car' (that is, a set of
// bodies and links which are grouped within this class; so it is
// easier to manage data structures in this example).
class MySimpleCar {
public:
// THE DATA
double throttle; // actual value 0...1 of gas throttle.
double conic_tau; // the transmission ratio of the conic gears at the rear axle
double gear_tau; // the actual tau of the gear
double max_motor_torque; // the max torque of the motor [Nm];
double max_motor_speed; // the max rotation speed of the motor [rads/s]
// .. chassis:
std::shared_ptr<ChBody> chassis;
// .. right front suspension:
std::shared_ptr<ChBody> spindleRF;
std::shared_ptr<ChBody> wheelRF;
// .. left front suspension:
std::shared_ptr<ChBody> spindleLF;
std::shared_ptr<ChBody> wheelLF;
// .. right back suspension:
std::shared_ptr<ChBody> spindleRB;
std::shared_ptr<ChBody> wheelRB;
// .. left back suspension:
std::shared_ptr<ChBody> spindleLB;
std::shared_ptr<ChBody> wheelLB;
// THE FUNCTIONS
// Build and initialize the car, creating all bodies corresponding to
// the various parts and adding them to the physical system - also creating
// and adding constraints to the system.
MySimpleCar(ChSystemNSC& my_system,
ISceneManager* msceneManager,
IVideoDriver* mdriver
) {
throttle = 0; // initially, gas throttle is 0.
conic_tau = 0.2;
gear_tau = 0.3;
max_motor_torque = 80;
max_motor_speed = 800;
// Texture for wheels
auto texture = chrono_types::make_shared<ChTexture>();
texture->SetTextureFilename(GetChronoDataFile("textures/bluewhite.png"));
// Contact materials for the various components
auto chassis_mat = chrono_types::make_shared<ChMaterialSurfaceNSC>();
auto wheel_mat = chrono_types::make_shared<ChMaterialSurfaceNSC>();
wheel_mat->SetFriction(1.0f);
// --- The car body ---
chassis = chrono_types::make_shared<ChBodyEasyBox>(1, 0.5, 3, 1.0, true, true, chassis_mat);
chassis->SetPos(ChVector<>(0, 1, 0));
chassis->SetMass(150);
chassis->SetInertiaXX(ChVector<>(4.8, 4.5, 1));
chassis->SetBodyFixed(false);
// --- Right Front suspension ---
// ..the car right-front spindle
spindleRF = chrono_types::make_shared<ChBodyEasyBox>(0.1, 0.4, 0.4, 1.0, true, false);
spindleRF->SetPos(ChVector<>(1.3, 1, 1));
spindleRF->SetMass(8);
spindleRF->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// ..the car right-front wheel
wheelRF = chrono_types::make_shared<ChBodyEasyCylinder>(0.45, 0.3, 1.0, true, true, wheel_mat);
wheelRF->SetPos(ChVector<>(1.5, 1, 1));
wheelRF->SetRot(chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Z));
wheelRF->SetMass(3);
wheelRF->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// .. create the revolute joint between the wheel and the spindle
ChCoordsys<>(ChVector<>(1.5, 1, 1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. impose distance between two parts (as a massless rod with two spherical joints at the end)
link_distRFU1->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 1.2, 1.2), ChVector<>(1.25, 1.2, 1));
link_distRFU2->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 1.2, 0.8), ChVector<>(1.25, 1.2, 1));
link_distRFL1->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 0.8, 1.2), ChVector<>(1.25, 0.8, 1));
link_distRFL2->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 0.8, 0.8), ChVector<>(1.25, 0.8, 1));
// .. create the spring between the truss and the spindle
link_springRF->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 1.2, 1.0), ChVector<>(1.25, 0.8, 1));
// .. create the rod for steering the wheel
link_distRSTEER->Initialize(chassis, spindleRF, false, ChVector<>(0.5, 1.21, 1.4), ChVector<>(1.25, 1.21, 1.3));
// --- Left Front suspension ---
// ..the car right-front spindle
spindleLF = chrono_types::make_shared<ChBodyEasyBox>(0.1, 0.4, 0.4, 1.0, true, false);
spindleLF->SetPos(ChVector<>(-1.3, 1, 1));
spindleLF->SetMass(8);
spindleLF->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// ..the car left-front wheel
wheelLF = chrono_types::make_shared<ChBodyEasyCylinder>(0.45, 0.3, 1.0, true, true, wheel_mat);
wheelLF->SetPos(ChVector<>(-1.5, 1, 1));
wheelLF->SetRot(chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Z));
wheelLF->SetMass(3);
wheelLF->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// .. create the revolute joint between the wheel and the spindle
ChCoordsys<>(ChVector<>(-1.5, 1, 1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. impose distance between two parts (as a massless rod with two spherical joints at the end)
link_distLFU1->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 1.2, 1.2), ChVector<>(-1.25, 1.2, 1));
link_distLFU2->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 1.2, 0.8), ChVector<>(-1.25, 1.2, 1));
link_distLFL1->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 0.8, 1.2), ChVector<>(-1.25, 0.8, 1));
link_distLFL2->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 0.8, 0.8), ChVector<>(-1.25, 0.8, 1));
// .. create the spring between the truss and the spindle
link_springLF->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 1.2, 1.0), ChVector<>(-1.25, 0.8, 1));
// .. create the rod for steering the wheel
link_distLSTEER->Initialize(chassis, spindleLF, false, ChVector<>(-0.5, 1.21, 1.4),
ChVector<>(-1.25, 1.21, 1.3));
// --- Right Back suspension ---
// ..the car right-back spindle
spindleRB = chrono_types::make_shared<ChBodyEasyBox>(0.1, 0.4, 0.4, 1.0, true, false);
spindleRB->SetPos(ChVector<>(1.3, 1, -1));
spindleRB->SetMass(8);
spindleRB->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// ..the car right-back wheel
wheelRB = chrono_types::make_shared<ChBodyEasyCylinder>(0.45, 0.3, 1.0, true, true, wheel_mat);
wheelRB->SetPos(ChVector<>(1.5, 1, -1));
wheelRB->SetRot(chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Z));
wheelRB->SetMass(3);
wheelRB->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// .. create the revolute joint between the wheel and the spindle
ChCoordsys<>(ChVector<>(1.5, 1, -1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. create the motor transmission joint between the wheel and the truss (assuming small changes of alignment)
ChFrame<>(ChVector<>(1.5, 1, -1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. impose distance between two parts (as a massless rod with two spherical joints at the end)
link_distRBU1->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 1.2, -1.2), ChVector<>(1.25, 1.2, -1));
link_distRBU2->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 1.2, -0.8), ChVector<>(1.25, 1.2, -1));
link_distRBL1->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 0.8, -1.2), ChVector<>(1.25, 0.8, -1));
link_distRBL2->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 0.8, -0.8), ChVector<>(1.25, 0.8, -1));
// .. create the spring between the truss and the spindle
link_springRB->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 1.2, -1.0), ChVector<>(1.25, 0.8, -1));
// .. create the rod for avoid the steering of the wheel
link_distRBlat->Initialize(chassis, spindleRB, false, ChVector<>(0.5, 1.21, -1.4),
ChVector<>(1.25, 1.21, -1.3));
// --- Left Back suspension ---
// ..the car right-back spindle
spindleLB = chrono_types::make_shared<ChBodyEasyBox>(0.1, 0.4, 0.4, 1.0, true, false);
spindleLB->SetPos(ChVector<>(-1.3, 1, -1));
spindleLB->SetMass(8);
spindleLB->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// ..the car left-back wheel
wheelLB = chrono_types::make_shared<ChBodyEasyCylinder>(0.45, 0.3, 1.0, true, true, wheel_mat);
wheelLB->SetPos(ChVector<>(-1.5, 1, -1));
wheelLB->SetRot(chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Z));
wheelLB->SetMass(3);
wheelLB->SetInertiaXX(ChVector<>(0.2, 0.2, 0.2));
// .. create the revolute joint between the wheel and the spindle
ChCoordsys<>(ChVector<>(-1.5, 1, -1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. create the motor transmission joint between the wheel and the truss (assuming small changes of alignment)
ChFrame<>(ChVector<>(-1.5, 1, -1), chrono::Q_from_AngAxis(CH_C_PI / 2, VECT_Y)));
// .. impose distance between two parts (as a massless rod with two spherical joints at the end)
link_distLBU1->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 1.2, -1.2), ChVector<>(-1.25, 1.2, -1));
link_distLBU2->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 1.2, -0.8), ChVector<>(-1.25, 1.2, -1));
link_distLBL1->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 0.8, -1.2), ChVector<>(-1.25, 0.8, -1));
link_distLBL2->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 0.8, -0.8), ChVector<>(-1.25, 0.8, -1));
// .. create the spring between the truss and the spindle
link_springLB->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 1.2, -1.0), ChVector<>(-1.25, 0.8, -1));
// .. create the rod for avoid the steering of the wheel
link_distLBlat->Initialize(chassis, spindleLB, false, ChVector<>(-0.5, 1.21, -1.4),
ChVector<>(-1.25, 1.21, -1.3));
}
// Delete the car object, deleting also all bodies corresponding to
// the various parts and removing them from the physical system. Also
// removes constraints from the system.
~MySimpleCar() {
ChSystem* mysystem = spindleRF->GetSystem(); // trick to get the system here
}
// This can be used, at each time step, to compute the actual value of torque
// transmitted to the wheels, according to gas throttle / speed / gear value.
// The following is a very simplified model (the torque curve of the motor is linear
// and no latency or inertial or clutch effects in gear train are considered.)
double ComputeWheelTorque() {
// Assume clutch is never used. Given the kinematics of differential,
// the speed of the engine transmission shaft is the average of the two wheel speeds,
// multiplied the conic gear transmission ratio inversed:
double shaftspeed =
// The motorspeed is the shaft speed multiplied by gear ratio inversed:
double motorspeed = (1.0 / this->gear_tau) * shaftspeed;
// The torque depends on speed-torque curve of the motor: here we assume a
// very simplified model a bit like in DC motors:
double motortorque = max_motor_torque - motorspeed * (max_motor_torque / max_motor_speed);
// Motor torque is linearly modulated by throttle gas value:
motortorque = motortorque * this->throttle;
// The torque at motor shaft:
double shafttorque = motortorque * (1.0 / this->gear_tau);
// The torque at wheels - for each wheel, given the differential transmission,
// it is half of the shaft torque (multiplied the conic gear transmission ratio)
double singlewheeltorque = 0.5 * shafttorque * (1.0 / this->conic_tau);
// Set the wheel torque in both 'motor' links, connecting the wheels to the truss;
mfun->Set_yconst(singlewheeltorque);
mfun->Set_yconst(singlewheeltorque);
// debug:print infos on screen:
// GetLog() << "motor torque="<< motortorque<< " speed=" << motorspeed << " wheel torqe=" << singlewheeltorque
// <<"\n";
// If needed, return also the value of wheel torque:
return singlewheeltorque;
}
};
// Define a MyEventReceiver class which will be used to manage input
// from the GUI graphical user interface (the interface will
// be created with the basic -yet flexible- platform
// independent toolset of Irrlicht).
public:
// store pointer to physical system & other stuff so we can tweak them by user keyboard
msystem = asystem;
mcar = acar;
// ..add a GUI slider to control gas throttle via mouse
scrollbar_throttle = mdevice->getGUIEnvironment()->addScrollBar(true, rect<s32>(10, 85, 150, 100), 0, 100);
scrollbar_throttle->setMax(100);
scrollbar_throttle->setPos(0);
text_throttle = mdevice->getGUIEnvironment()->addStaticText(L"Throttle", rect<s32>(155, 85, 300, 100), false);
// ..add a GUI slider to control steering via mouse
scrollbar_steer = mdevice->getGUIEnvironment()->addScrollBar(true, rect<s32>(10, 105, 150, 120), 0, 101);
scrollbar_steer->setMax(100);
scrollbar_steer->setPos(50);
text_steer = mdevice->getGUIEnvironment()->addStaticText(L"Steering", rect<s32>(155, 105, 300, 120), false);
// ..add a GUI text and GUI slider to control the stiffness
scrollbar_FspringK = mdevice->getGUIEnvironment()->addScrollBar(true, rect<s32>(10, 125, 150, 140), 0, 102);
scrollbar_FspringK->setMax(100);
scrollbar_FspringK->setPos(
(s32)(50 + 50.0 * (acar->link_springRF->GetSpringCoefficient() - 80000.0) / 60000.0));
text_FspringK =
mdevice->getGUIEnvironment()->addStaticText(L"Spring K [N/m]:", rect<s32>(155, 125, 300, 140), false);
// ..add a GUI text and GUI slider to control the damping
scrollbar_FdamperR = mdevice->getGUIEnvironment()->addScrollBar(true, rect<s32>(10, 145, 150, 160), 0, 103);
scrollbar_FdamperR->setMax(100);
scrollbar_FdamperR->setPos((s32)(50 + 50.0 * (acar->link_springRF->GetDampingCoefficient() - 800.0) / 800.0));
text_FdamperR =
mdevice->getGUIEnvironment()->addStaticText(L"Damper R [Ns/m]:", rect<s32>(155, 145, 300, 160), false);
// ..add a GUI text and GUI slider to control the original undeformed spring length
scrollbar_FspringL = mdevice->getGUIEnvironment()->addScrollBar(true, rect<s32>(10, 165, 150, 180), 0, 104);
scrollbar_FspringL->setMax(100);
scrollbar_FspringL->setPos((s32)(50 + 50.0 * (acar->link_springRF->GetRestLength() - 0.9) / 0.1));
text_FspringL =
mdevice->getGUIEnvironment()->addStaticText(L"Spring L [m]:", rect<s32>(155, 165, 300, 180), false);
}
bool OnEvent(const SEvent& event) {
// check if user moved the sliders with mouse..
if (event.EventType == EET_GUI_EVENT) {
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = mdevice->getGUIEnvironment();
switch (event.GUIEvent.EventType) {
case EGET_SCROLL_BAR_CHANGED:
if (id == 101) // id of 'steer' slider..
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
double newsteer = 0.18 * (((double)(pos - 50)) / 50.0);
// set the steering, moving horizontally the endpoints of the steer rod endpoint on truss.
}
if (id == 102) // id of 'spring stiffness' slider..
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
double newstiff = 80000 + 60000 * (((double)(pos - 50)) / 50.0);
// set the stiffness of all 4 springs
// show stiffness as formatted text in interface screen
char message[150];
sprintf(message, "Spring K [N/m]: %g", newstiff);
std::cout << "K = " << newstiff << std::endl;
text_FspringK->setText(core::stringw(message).c_str());
}
if (id == 103) // id of 'damping' slider..
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
double newdamping = 800 + 800 * (((double)(pos - 50)) / 50.0);
// set the damping of all 4 springs
// show stiffness as formatted text in interface screen
char message[150];
sprintf(message, "Damper R [Ns/m]: %g", newdamping);
text_FdamperR->setText(core::stringw(message).c_str());
}
if (id == 104) // id of 'spring rest length' slider..
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
double newlength = 0.9 + 0.1 * (((double)(pos - 50)) / 50.0);
// set the rest length of all 4 springs
// show stiffness as formatted text in interface screen
char message[50];
sprintf(message, "Spring L [m]: %g", newlength);
text_FspringL->setText(core::stringw(message).c_str());
}
if (id == 100) // id of 'throttle' slider..
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
double newthrottle = ((double)(pos)) / 100.0;
// Set the throttle value of car (the torque transmitted
// to wheels depends on throttle, speed, transmission gear, so
// computed by MySimplifiedCar::ComputeWheelTorque(),
this->mcar->throttle = newthrottle;
}
break;
default:
break;
}
}
return false;
}
private:
ChSystemNSC* msystem;
IrrlichtDevice* mdevice;
MySimpleCar* mcar;
IGUIStaticText* text_steer;
IGUIScrollBar* scrollbar_steer;
IGUIStaticText* text_FspringK;
IGUIScrollBar* scrollbar_FspringK;
IGUIStaticText* text_FdamperR;
IGUIScrollBar* scrollbar_FdamperR;
IGUIStaticText* text_FspringL;
IGUIScrollBar* scrollbar_FspringL;
IGUIStaticText* text_throttle;
IGUIScrollBar* scrollbar_throttle;
};
//
// This is the program which is executed
//
int main(int argc, char* argv[]) {
GetLog() << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n";
//
// HERE YOU CREATE THE MECHANICAL SYSTEM OF CHRONO...
//
// 1- Create a Chrono physical system: all bodies and constraints
// will be handled by this ChSystemNSC object.
ChSystemNSC my_system;
// 2.- Create the Irrlicht visualization.
ChIrrApp application(&my_system, L"Simple vehicle suspension", core::dimension2d<u32>(640, 480), false);
// 3- Create the rigid bodies of the simpified car suspension mechanical system
// maybe setting position/mass/inertias of
// their center of mass (COG) etc.
// ..the world
auto texture = chrono_types::make_shared<ChTexture>();
texture->SetTextureFilename(GetChronoDataFile("textures/blue.png"));
// ..contact materials
auto ground_mat = chrono_types::make_shared<ChMaterialSurfaceNSC>();
ground_mat->SetSfriction(1.0);
ground_mat->SetKfriction(1.0);
auto obstacle_mat = chrono_types::make_shared<ChMaterialSurfaceNSC>();
// ..ground body
auto my_ground = chrono_types::make_shared<ChBodyEasyBox>(60, 2, 60, 1.0, true, true, ground_mat);
my_ground->SetPos(ChVector<>(0, -1, 0));
my_ground->SetBodyFixed(true);
// ..some obstacles on the ground
for (int i = 0; i < 6; i++) {
auto my_obstacle = chrono_types::make_shared<ChBodyEasyBox>(1, 0.1, 0.5, 60.0, true, true, obstacle_mat);
my_obstacle->SetPos(ChVector<>(20 * ChRandom(), 2, 20 * ChRandom()));
my_obstacle->SetMass(3);
}
// ..the car (this class - see above - is a 'set' of bodies and links, automatically added at creation)
MySimpleCar* mycar = new MySimpleCar(my_system, application.GetSceneManager(), application.GetVideoDriver());
//
// CREATE A CUSTOM COMPOSITE MATERIAL
//
// Suppose you want that some places have different friction coefficient values,
// how can you do this? To change the default combination law for the friction
// coefficient of a contact pair, use a 'callback object'. This will be called for
// each contact point, as it is created, and can be used to modify the composite
// contact material properties.
class MyContactCallback : public ChContactContainer::AddContactCallback {
public:
ChMaterialComposite* const material) override {
// Downcast to appropriate composite material type
auto mat = static_cast<ChMaterialCompositeNSC* const>(material);
if (contactinfo.vpA.x() > 0)
mat->static_friction = 0.7f; // On the right of the plane, less friction...
else
mat->static_friction = 1.0f; // On the left of the plane, more friction...
};
};
// Use the above callback to process each contact as it is created.
auto mycontact_callback = chrono_types::make_shared<MyContactCallback>();
// Bind visualization assets.
application.AssetBindAll();
application.AssetUpdateAll();
//
// USER INTERFACE
//
// Create some graphical-user-interface (GUI) items to show on the screen.
// This requires an event receiver object -see above.
//
// SETTINGS
//
my_system.SetSolverMaxIterations(20); // the higher, the easier to keep the constraints satisifed.
//
// THE SOFT-REAL-TIME CYCLE, SHOWING THE SIMULATION
//
// Timer for enforcing sodt real-time
ChRealtimeStepTimer realtime_timer;
double time_step = 0.005;
while (application.GetDevice()->run()) {
// Irrlicht must prepare frame to draw
application.BeginScene(true, true, SColor(255, 140, 161, 192));
// Irrlicht now draws simple lines in 3D world representing a
// skeleton of the mechanism, in this instant:
//
// .. draw solid 3D items (boxes, cylinders, shapes) belonging to Irrlicht scene, if any
application.DrawAll();
// .. draw a grid (rotated so that it's horizontal)
ChIrrTools::drawGrid(application.GetVideoDriver(), 2, 2, 30, 30,
ChCoordsys<>(ChVector<>(0, 0.01, 0), Q_from_AngX(CH_C_PI_2)),
video::SColor(255, 80, 130, 130), true);
// .. draw GUI user interface items (sliders, buttons) belonging to Irrlicht screen, if any
application.GetIGUIEnvironment()->drawAll();
// .. draw the distance constraints (the massless rods) as simplified lines
// .. draw the spring constraints as simplified spring helix
linkdist->GetEndPoint2Abs(), video::SColor(255, 0, 20, 0), true);
linkspring->GetPoint2Abs(), video::SColor(255, 150, 20, 20), 80, 10, true);
}
}
// wheels and truss, depends on many parameters (gear, throttle, etc):
mycar->ComputeWheelTorque();
// ADVANCE SYSTEM STATE BY ONE STEP
my_system.DoStepDynamics(time_step);
// Enforce soft real-time
realtime_timer.Spin(time_step);
// Irrlicht must finish drawing the frame
application.EndScene();
}
if (mycar)
delete mycar;
return 0;
}
std::string GetChronoDataFile(const std::string &filename)
Obtain the complete path to the specified filename, given relative to the Chrono data directory (thre...
Definition: ChGlobal.cpp:95
static void drawGrid(irr::video::IVideoDriver *driver, double ustep=0.1, double vstep=0.1, int nu=20, int nv=20, ChCoordsys<> mpos=CSYSNORM, irr::video::SColor mcol=irr::video::SColor(50, 80, 110, 110), bool use_Zbuffer=false)
Easy-to-use function to draw grids in 3D space, with given orientation, color and spacing.
Definition: ChIrrTools.cpp:695
static void add_typical_Camera(irr::IrrlichtDevice *device, irr::core::vector3df mpos=irr::core::vector3df(0, 0, -8), irr::core::vector3df mtarg=irr::core::vector3df(0, 0, 0))
A very basic and simple function which is just a shortcut to avoid lot of typing when someone wants t...
Definition: ChIrrWizard.cpp:53
COORDSYS:
Definition: ChCoordsys.h:38
ChLog & GetLog()
Global function to get the current ChLog object.
Definition: ChLog.cpp:39
Attach a link to the underlying assembly.
Definition: ChSystem.h:268
static void add_typical_Logo(irr::IrrlichtDevice *device, const std::string &mlogofilename=GetChronoDataFile("logo_chronoengine_alpha.png"))
A very basic and simple function which is just a shortcut to avoid lot of typing when someone wants t...
Definition: ChIrrWizard.cpp:20
static void add_typical_Sky(irr::IrrlichtDevice *device, const std::string &mtexturedir=GetChronoDataFile("skybox/"))
A very basic and simple function which is just a shortcut to avoid lot of typing when someone wants t...
Definition: ChIrrWizard.cpp:40
static void add_typical_Lights(irr::IrrlichtDevice *device, irr::core::vector3df pos1=irr::core::vector3df(30.f, 100.f, 30.f), irr::core::vector3df pos2=irr::core::vector3df(30.f, 80.f, -30.f), double rad1=290, double rad2=190, irr::video::SColorf col1=irr::video::SColorf(0.7f, 0.7f, 0.7f, 1.0f), irr::video::SColorf col2=irr::video::SColorf(0.7f, 0.8f, 0.8f, 1.0f))
A very basic and simple function which is just a shortcut to avoid lot of typing when someone wants t...
Definition: ChIrrWizard.cpp:25
Remove a link from this assembly.
Definition: ChSystem.h:297
ChFrame: a class for coordinate systems in 3D space.
Definition: ChFrame.h:42
Class to add some GUI to Irrlicht+ChronoEngine applications.
Definition: ChIrrApp.h:29
ChQuaternion< double > Q_from_AngAxis(double angle, const ChVector< double > &axis)
Get the quaternion from an angle of rotation and an axis, defined in abs coords.
Definition: ChQuaternion.cpp:100
virtual void EndScene()
Call this to end the scene draw at the end of each animation frame.
Definition: ChIrrAppInterface.cpp:634
Namespace with classes for the Irrlicht module.
Definition: ChApiIrr.h:48
Class for a timer which attempts to enforce soft real-time.
Definition: ChRealtimeStep.h:25
static void drawSegment(irr::video::IVideoDriver *driver, ChVector<> mstart, ChVector<> mend, irr::video::SColor mcol=irr::video::SColor(255, 0, 0, 0), bool use_Zbuffer=false)
Easy-to-use function to draw segment lines in 3D space, with given color.
Definition: ChIrrTools.cpp:594
Class defining basic geometric information for collision pairs.
Definition: ChCollisionInfo.h:27
void Spin(double step)
Call this function INSIDE the simulation loop, just ONCE per loop (preferably as the last call in the...
Definition: ChRealtimeStep.h:34
Definition of general purpose 3d vector variables, such as points in 3D.
Definition: ChVector.h:35
Physical system.
Definition: ChSystem.h:69
int DoStepDynamics(double step_size)
Advances the dynamical simulation for a single step, of length step_size.
Definition: ChSystem.cpp:1300
virtual void AddBody(std::shared_ptr< ChBody > body)
Attach a body to the underlying assembly.
Definition: ChSystem.h:265
void SetSolverMaxIterations(int max_iters)
Set the maximum number of iterations, if using an iterative solver.
Definition: ChSystem.cpp:188
ChVector vpA
coll.point on A, in abs coords
Definition: ChCollisionInfo.h:33
Real & x()
Definition: ChVector.h:49
double ChRandom()
Returns random value in (0..1) interval with Park-Miller method.
Definition: ChMathematics.cpp:53
static void drawSpring(irr::video::IVideoDriver *driver, double radius, ChVector<> start, ChVector<> end, irr::video::SColor mcol=irr::video::SColor(255, 0, 0, 0), int mresolution=65, double turns=5, bool use_Zbuffer=false)
Easy-to-use function to draw a spring in 3D space, with given color.
Definition: ChIrrTools.cpp:652
Base class for composite material for a contact pair.
Definition: ChMaterialSurface.h:86
virtual void BeginScene(bool backBuffer=true, bool zBuffer=true, irr::video::SColor color=irr::video::SColor(255, 0, 0, 0))
Call this to clean the canvas at the beginning of each animation frame.
Definition: ChIrrAppInterface.cpp:617
Main namespace for the Chrono package.
Definition: ChAsset.cpp:18