Thus, we will build a robot with two motorised wheels and one passive caster wheel useful for balancing the robot.
Note that if there are no contacts or collisions in your system, it is indifferent to use ChSystemNSC or ChSystemSMC.
Next are the helper functions that set up the various components. Note that we need to enable collisions. We also need to set explicitly the velocity of the chassis explicitly. The linear velocity of a differential drive system is given by
where \(r\) is the radius of the wheel and \(\omega_i\) if the angular velocity of motor \(i\) in rad/s. We can use this relationship in a control simulation in order to control either the linear velocity or the motor speed.
{
using namespace chrono;
using namespace chrono::irrlicht;
auto* driver = vis.GetVideoDriver();
driver->draw3DLine(
{0, 0, 0},
{static_cast<float>(scale), 0, 0},
irr::video::SColor(255, 255, 0, 0));
driver->draw3DLine(
{0, 0, 0},
{0,
static_cast<float>(
scale), 0},
irr::video::SColor(255, 0, 255, 0));
driver->draw3DLine(
{0, 0, 0},
{0, 0,
static_cast<float>(
scale)},
irr::video::SColor(255, 0, 0, 255));
}
{
auto material = chrono_types::make_shared<ChContactMaterialNSC>();
material->SetFriction(0.8f);
material->SetRestitution(0.1f);
return material;
}
auto build_floor(std::shared_ptr<ChContactMaterialNSC> material)
{
auto floor = chrono_types::make_shared<chrono::ChBodyEasyBox>(
5, 5, 0.1,
1000,
true, true, material);
floor->SetPos(chrono::ChVector3d(0,0,-0.05));
floor->SetFixed(true);
floor->EnableCollision(true);
return floor;
}
auto build_chassis(std::shared_ptr<ChContactMaterialNSC> material)
{
auto chassis = chrono_types::make_shared<ChBodyEasyBox>(
1000,
true, true, material);
chassis->SetPos(pos);
chrono::ChVector3d vel(0.5, 0.0, 0.0);
chassis->SetPosDt(vel);
chassis->EnableCollision(true);
return chassis;
}
auto build_wheel(std::shared_ptr<ChContactMaterialNSC> material,
const chrono::ChVector3d& pos)
{
auto wheel = chrono_types::make_shared<chrono::ChBodyEasyCylinder>(
chrono::ChAxis::Y,
1000,
true, true, material);
wheel->SetPos(pos);
wheel->EnableCollision(true);
return wheel;
}
auto build_motor(std::shared_ptr<ChBodyEasyCylinder> wheel,
std::shared_ptr<ChBodyEasyBox> chassis,
std::shared_ptr<ChFunctionConst> speed_func,
const chrono::ChVector3d& pos)
{
auto motor = chrono_types::make_shared<chrono::ChLinkMotorRotationSpeed>();
chrono::ChQuaternion<> rot = chrono::QuatFromAngleX(chrono::CH_PI_2);
motor->Initialize(
wheel,
chassis,
chrono::ChFrame<>(pos, rot)
);
motor->SetSpeedFunction(speed_func);
return motor;
}
{
auto caster = chrono_types::make_shared<ChBodyEasySphere>(
1000,
true,
true,
material);
caster->SetPos(chrono::ChVector3d(0.2, 0, 0.05));
caster->EnableCollision(true);
return caster;
}
std::shared_ptr<ChBodyEasyBox> chassis)
{
auto caster_joint = chrono_types::make_shared<ChLinkLockRevolute>();
caster_joint->Initialize(
caster,
chassis,
return caster_joint;
}
}
const GeomPoint< spacedim, T > scale(const GeomPoint< spacedim, T > &t, T factor)
scale the given point by facto and returns a copyr. This function does not change the entries of t.
Definition geom_point.h:421
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20
Definition chrono_rigid_body_simulation.cpp:19
auto build_wheel(std::shared_ptr< ChContactMaterialNSC > material, const chrono::ChVector3d &pos)
Definition chrono_rigid_body_simulation.cpp:82
const real_t CHASSIS_HEIGHT
Definition chrono_rigid_body_simulation.cpp:26
auto build_caster_wheel(std::shared_ptr< ChContactMaterialNSC > material)
Definition chrono_rigid_body_simulation.cpp:104
auto build_chassis(std::shared_ptr< ChContactMaterialNSC > material)
Definition chrono_rigid_body_simulation.cpp:68
auto build_floor(std::shared_ptr< ChContactMaterialNSC > material)
Definition chrono_rigid_body_simulation.cpp:55
void draw_world_axes(chrono::irrlicht::ChVisualSystemIrrlicht &vis, real_t scale=1.0)
Definition chrono_rigid_body_simulation.cpp:30
auto build_motor(std::shared_ptr< ChBodyEasyCylinder > wheel, std::shared_ptr< ChBodyEasyBox > chassis, std::shared_ptr< ChFunctionConst > speed_func, const chrono::ChVector3d &pos)
Definition chrono_rigid_body_simulation.cpp:92
auto build_caster_joint(std::shared_ptr< ChBodyEasySphere > caster, std::shared_ptr< ChBodyEasyBox > chassis)
Definition chrono_rigid_body_simulation.cpp:118
const real_t WHEEL_RADIUS
Definition chrono_rigid_body_simulation.cpp:25
auto build_generic_material()
Definition chrono_rigid_body_simulation.cpp:47
const real_t WHEEL_WIDTH
Definition chrono_rigid_body_simulation.cpp:27
const real_t CASTER_RADIUS
Definition chrono_rigid_body_simulation.cpp:28
ChSystemNSC system;
system.SetCollisionSystemType(chrono::ChCollisionSystem::Type::BULLET);
system.Add(floor);
system.Add(chassis);
system.Add(left_wheel);
system.Add(right_wheel);
chrono_types::make_shared<chrono::ChFunctionConst>(-4.5), chrono::ChVector3d(0,0.2,0.1));
chrono_types::make_shared<chrono::ChFunctionConst>(-4.5), chrono::ChVector3d(0,-0.2,0.1));
system.Add(motor_left);
system.Add(motor_right);
system.Add(caster);
system.Add(caster_joint);
chrono::irrlicht::ChVisualSystemIrrlicht vis;
vis.AttachSystem(&system);
vis.SetWindowSize(1280,720);
vis.SetWindowTitle("A rigid body simulation with Chrono");
vis.Initialize();
vis.AddSkyBox();
vis.AddLogo();
vis.AddSkyBox();
vis.AddCamera({0, -2, 1}, {0, 0, 0});
vis.AddTypicalLights();
vis.BindAll();
while (vis.Run()) {
vis.BeginScene();
vis.Render();
auto position = chassis -> GetPos();
std::cout << position <<std::endl;
system.DoStepDynamics(step_size);
vis.EndScene();
}
return 0;
}
int main()
Definition discounted_returns.cpp:19
const real_t G
Acceleration due to gravity m/secs.
Definition bitsim_consts.h:68