Skip to content

Latest commit

 

History

History
141 lines (109 loc) · 4.95 KB

File metadata and controls

141 lines (109 loc) · 4.95 KB

\page bitrl_example_13 BitRL Example 13 Using chrono::ChSystemSMC

Example \ref bitrl_example_11 discussed ChBody. Specifically, how to create a ChBodyEasyBox. Understanding rigid bodies is fundamental to robotics. In this example we will discuss ChSystem. This is the cornerstone of a Chrono simulation. Most information in this example can be found in the official doumentation here: Simulation system. A ChSystem is an abstract class. The Chrono library provides the following subclasses:

  • ChSystemNSC for Non Smooth Contacts (NSC): in case of contacts a complementarity solver will take care of them using non-smooth dynamics; this is very efficient even with large time steps.
  • ChSystemSMC for SMooth Contacts (SMC): contacts are handled using penalty methods, i.e. contacts are deformable

Note that if there are no contacts or collisions in your system, it is indifferent to use ChSystemNSC or ChSystemSMC. In this example we will use the \ref bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot "bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot" class to simulate a differential drive system using Chrono. The \ref bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot "bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot" follows the Turtlebot robot model defined in Chrono. You will need the mesh files from the Chrono project in order to visualize the robot. These files should be place in the \ref ROBOTS_DATA_DIR directory under the diff_drive_robot subdirectory of the project. Below is the driver code.

@code{.cpp} #include "bitrl/bitrl_config.h"

#ifdef BITRL_CHRONO

#include "bitrl/bitrl_types.h"

#ifdef BITRL_LOG #define BOOST_LOG_DYN_LINK #include <boost/log/trivial.hpp> #endif

#include "chrono/core/ChRealtimeStep.h" #include "chrono/physics/ChSystemNSC.h" #include <chrono/physics/ChBodyEasy.h> #include <chrono_irrlicht/ChVisualSystemIrrlicht.h> #include "bitrl/rigid_bodies/chrono_robots/diff_drive_robot.h"

#include #include

namespace example_13 { using namespace bitrl; using namespace chrono::irrlicht;

// constants we will be using further below const uint_t WINDOW_HEIGHT = 800; const uint_t WINDOW_WIDTH = 1024; const real_t DT = 0.01; const real_t SIM_TIME = 5.0; const std::string WINDOW_TITLE( "Example 13");

void prepare_visualization(chrono::irrlicht::ChVisualSystemIrrlicht& visual) { visual.SetWindowSize(WINDOW_WIDTH, WINDOW_WIDTH); //WINDOW_HEIGHT); visual.SetWindowTitle(WINDOW_TITLE); visual.Initialize();

visual.AddLogo();
visual.AddSkyBox();
visual.AddCamera({0, -2, 1}, {0, 0, 0});
visual.AddTypicalLights();
visual.BindAll();

}

} // namespace example_13

int main() { using namespace example_13; chrono::ChSystemNSC sys; sys.SetGravitationalAcceleration(chrono::ChVector3d(0, 0, -9.81));

sys.SetCollisionSystemType(chrono::ChCollisionSystem::Type::BULLET);
chrono::ChCollisionModel::SetDefaultSuggestedEnvelope(0.0025);
chrono::ChCollisionModel::SetDefaultSuggestedMargin(0.0025);

auto floor_mat = chrono_types::make_shared<chrono::ChContactMaterialNSC>();
auto mfloor = chrono_types::make_shared<chrono::ChBodyEasyBox>(20, 20, 1, 1000, true, true, floor_mat);
mfloor->SetPos(chrono::ChVector3d(0, 0, -1));
mfloor->SetFixed(true);
mfloor->GetVisualShape(0)->SetTexture(chrono::GetChronoDataFile("textures/concrete.jpg"));
sys.Add(mfloor);

bitrl::rb::bitrl_chrono::CHRONO_DiffDriveRobot robot(sys,
                                             chrono::ChVector3d(0, 0, -0.45), chrono::QUNIT);

robot.init();
robot.set_motor_speed(bitrl::consts::maths::PI, 0);
robot.set_motor_speed(bitrl::consts::maths::PI, 1);

chrono::irrlicht::ChVisualSystemIrrlicht visual;
prepare_visualization(visual);
visual.AttachSystem(&sys);

// Simulation loop

// Timer for enforcing soft real-time
chrono::ChRealtimeStepTimer realtime_timer;

// bool removed = false;
while (visual.Run()) {
    // Irrlicht must prepare frame to draw
    visual.BeginScene();

    // Irrlicht now draws simple lines in 3D world representing a
    // skeleton of the mechanism, in this instant:
    //
    // .. draw items belonging to Irrlicht scene, if any
    visual.Render();
    // .. draw a grid
    tools::drawGrid(&visual, 0.5, 0.5);
    // .. draw GUI items belonging to Irrlicht screen, if any
    visual.GetGUIEnvironment()->drawAll();

    // ADVANCE SYSTEM STATE BY ONE STEP
    sys.DoStepDynamics(DT);
    
    // Enforce soft real-time
    realtime_timer.Spin(DT);

    // Irrlicht must finish drawing the frame
    visual.EndScene();
}

return 0;

} #else #include int main() { std::cerr<<"You need PROJECTCHRONO configured with " <<"bitrl in order to run this example " <<"Reconfigure bitrl and set ENABLE_CHRONO=ON"<<std::endl; return 1; }

#endif @endcode