### Project Chrono Installation Guide Source: https://api.projectchrono.org/development/tutorial_install_chrono Details the prerequisites, optional support, third-party dependencies, configuration, building, testing, and installation steps for Project Chrono. ```APIDOC Install Chrono: Table of Contents: - Prerequisites: - Recommended compilers - Install CMake - Install a GUI git client - Optional support: - CUDA support - Thrust support - MPI support - OpenMP support - Third-party dependencies: - Install Eigen - Utility scripts for installing 3rd-party Chrono dependencies - Notes on 3rd-party Chrono dependencies - Configuring Chrono with CMake: - Using CMake through the GUI interface - Using CMake through the Curses interface - Building Chrono: - Visual Studio - Linux/make - MacOS/clang - Testing Chrono build - Installing Chrono Source Code Acquisition: - GitHub repository: https://github.com/projectchrono/chrono - Clone using git: https://git-scm.com/ Prerequisites: - C++ compiler - CMake build system ``` -------------------------------- ### Chrono Irrlicht Visualization Setup and Rendering Source: https://api.projectchrono.org/development/tutorial_demo_forklift Demonstrates the setup and rendering process using Chrono's Irrlicht visualization system. This includes initializing the visual system, setting window properties, adding lights, cameras, and handling the simulation loop. ```cpp vis->AttachSystem(sys); vis->SetWindowSize(800, 600); vis->SetWindowTitle("Forklift demo"); vis->Initialize(); vis->AddLogo(); vis->AddSkyBox(); vis->AddTypicalLights(); vis->AddCamera(ChVector3d(-6, 3, -6)); MyEventReceiver receiver(myforklift); vis->AddUserEventReceiver(&receiver); vis->GetGUIEnvironment()->addStaticText(L"Keys: steer=Q,W; throttle=A,Z; lift=S,X; bank=D,C", rect(150, 10, 430, 40), true); // Simulation loop double timestep = 0.005; ChRealtimeStepTimer realtime_timer; while (vis->Run()) { vis->BeginScene(); vis->Render(); sys.DoStepDynamics(timestep); vis->EndScene(); realtime_timer.Spin(timestep); } if (myforklift) delete myforklift; return 0; ``` -------------------------------- ### ProjectChrono API Documentation - Installation and Build Source: https://api.projectchrono.org/development/manual_core Guides users on how to install and build the Chrono simulation engine and how to build a project using Chrono. ```APIDOC Install and build Chrono: https://api.projectchrono.org/development/tutorial_install_chrono.html Build a project: https://api.projectchrono.org/development/tutorial_install_project.html ``` -------------------------------- ### Chrono Core Tutorials - MBS Crank Source: https://api.projectchrono.org/development/tutorial_table_of_content_chrono Demonstrates the setup of physical systems in Chrono, focusing on multi-body systems (MBS). This example includes links, bodies, and simple visualization, serving as a starting point for users. ```cpp #include "chrono/physics/ChSystemNSC.h" #include "chrono/physics/ChBodyEasy.h" #include "chrono/utils/ChUtilsCreators.h" int main() { chrono::ChSystemNSC sys; // Create a ground body auto ground = chrono::ChSharedPtr(new chrono::ChBody); ground->SetBodyFixed(true); sys.AddBody(ground); // Create a crank body auto crank = chrono::ChSharedPtr(new chrono::ChBody); crank->SetMass(1.0); crank->SetInertiaXX(chrono::ChVector<>(0.1, 0.1, 0.1)); sys.AddBody(crank); // Add a revolute joint to connect crank to ground auto revolute_joint = chrono::ChSharedPtr(new chrono::ChLinkRevolute); revolute_joint->Initialize(ground, crank, chrono::ChCoordsys<>(chrono::ChVector<>(0, 0, 0))); sys.AddLink(revolute_joint); // Simulation loop (simplified) double time_step = 0.01; for (double t = 0; t < 1.0; t += time_step) { sys.DoStepDynamics(time_step); } return 0; } ``` -------------------------------- ### Project Chrono Tutorials Source: https://api.projectchrono.org/development/index Offers basic examples for various features within Chrono, serving as a starting point for users. ```APIDOC Tutorials: Location: https://api.projectchrono.org/development/tutorial_root.html Purpose: Introduces users to Chrono's functionalities through simple, practical examples. ``` -------------------------------- ### Chrono Physics System Setup and Solver Configuration Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_shells Demonstrates setting up a Chrono physics system, adding bodies and constraints, and configuring the solver and integrator. Includes examples of using PardisoMKL solver and implicit Euler integrator. ```cpp auto mtruss = chrono_types::make_shared(); mtruss->SetFixed(true); sys.Add(mtruss); for (auto mendnode : nodes_left) { auto mlink = chrono_types::make_shared(false, true, false, true, false, true); mlink->Initialize(mendnode, mtruss, false, mendnode->Frame(), mendnode->Frame()); sys.Add(mlink); } for (auto mendnode : nodes_right) { auto mlink = chrono_types::make_shared(false, true, false, true, false, true); mlink->Initialize(mendnode, mtruss, false, mendnode->Frame(), mendnode->Frame()); sys.Add(mlink); } // Change solver to PardisoMKL auto mkl_solver = chrono_types::make_shared(); mkl_solver->LockSparsityPattern(true); sys.SetSolver(mkl_solver); // Change type of integrator: sys.SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT); ``` -------------------------------- ### Chrono Simulation Setup Source: https://api.projectchrono.org/development/tutorial_demo_forklift Initializes a Chrono physics system, sets the collision system type, and creates a ground plane with obstacles. It also instantiates the forklift and the visualization system. ```C++ // ----------------------------------------------------------------------------- int main(int argc, char* argv[]) { std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl; // Create a Chrono physical system [ChSystemNSC](https://api.projectchrono.org/development/classchrono_1_1_ch_system_n_s_c.html) sys; sys.[SetCollisionSystemType](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a0f4b913c70a99c06acbb39a32922fb3c)([ChCollisionSystem::Type::BULLET](https://api.projectchrono.org/development/classchrono_1_1_ch_collision_system.html#a60a83e68e6a182fb45048630f4663749a5fb9dc502beb6f75a2175f0ea535437d)); // Contact material for ground auto ground_mat = chrono_types::make_shared(); ground_mat->SetFriction(1.0f); // ..the world auto my_ground = chrono_types::make_shared(40, 2, 40, 1000, true, true, ground_mat); sys.[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(my_ground); my_ground->SetFixed(true); my_ground->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0, -1, 0)); my_ground->GetVisualShape(0)->SetTexture([GetChronoDataFile](https://api.projectchrono.org/development/namespacechrono.html#a3bf1da4bd1bc011eeba49d5db828fd53)("textures/concrete.jpg")); // ..some obstacles on the ground: for (int i = 0; i < 6; i++) { auto my_obstacle = chrono_types::make_shared(1, 0.5, 1, 200, true, true, ground_mat); sys.[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(my_obstacle); my_obstacle->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(20 * ChRandom::Get(), 2, 20 * ChRandom::Get())); my_obstacle->GetVisualShape(0)->SetTexture([GetChronoDataFile](https://api.projectchrono.org/development/namespacechrono.html#a3bf1da4bd1bc011eeba49d5db828fd53)("textures/cubetexture_wood.png")); } // ..the forklift (this class - see above - is a 'set' of bodies and links, automatically added at creation) MySimpleForklift* myforklift = new MySimpleForklift(&sys); // Create the Irrlicht visualization system auto vis = chrono_types::make_shared(); ``` -------------------------------- ### Chrono System Solver and Timestepper Setup Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_visualize Configures the physics system's solver and timestepper. This example sets the timestepper to EULER_IMPLICIT_LINEARIZED and uses the MINRES solver with specific iteration and tolerance settings, including enabling warm start and diagonal preconditioning. ```cpp // Solver settings sys.SetTimestepperType(chrono::ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED); auto solver = chrono_types::make_shared(); sys.SetSolver(solver); solver->SetMaxIterations(40); solver->SetTolerance(1e-10); solver->EnableDiagonalPreconditioner(true); solver->EnableWarmStart(true); solver->SetVerbose(false); ``` -------------------------------- ### Chrono System Setup and Analysis Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_basic Demonstrates setting up a Chrono system, adding bodies and constraints, configuring a linear solver, and performing a static linear analysis. It also shows how to output results. ```cpp auto truss = chrono_types::make_shared(); sys.Add(truss); truss->SetFixed(true); // Create a constraint between a node and the truss auto constraint1 = chrono_types::make_shared(); auto constraint2 = chrono_types::make_shared(); auto constraint3 = chrono_types::make_shared(); auto constraint4 = chrono_types::make_shared(); constraint1->Initialize(mnode1, truss); constraint2->Initialize(mnode2, truss); constraint3->Initialize(mnode3, truss); constraint4->Initialize(mnode4, truss); sys.Add(constraint1); sys.Add(constraint2); sys.Add(constraint3); sys.Add(constraint4); // Set no gravity // sys.SetGravitationalAcceleration(VNULL); // Perform a linear static analysis auto solver = chrono_types::make_shared(); sys.SetSolver(solver); solver->SetMaxIterations(100); solver->SetTolerance(1e-12); solver->EnableDiagonalPreconditioner(true); solver->SetVerbose(true); sys.DoStaticLinear(); // Output some results std::cout << "node5 displ: " << mnode5->GetPos() - mnode5->GetX0() << std::endl; std::cout << "node6 displ: " << mnode6->GetPos() - mnode6->GetX0() << std::endl; std::cout << "node7 displ: " << mnode7->GetPos() - mnode7->GetX0() << std::endl; std::cout << "node8 displ: " << mnode8->GetPos() - mnode8->GetX0() << std::endl; std::cout << "Element volume" << melement1->GetVolume() << std::endl; ``` -------------------------------- ### Chrono System Setup and Linear Static Analysis Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_basic Demonstrates how to initialize a ChSystem, add meshes and bodies, apply constraints, set a solver, and perform a linear static analysis. It also shows how to retrieve positions and reactions. ```C++ // Remember to add elements to the mesh! my_mesh->AddElement(melementA); // Remember to add the mesh to the system! sys.Add(my_mesh); // Create also a truss auto truss = chrono_types::make_shared(); truss->SetFixed(true); sys.Add(truss); // Create a constraint between a node and the truss auto constraintA = chrono_types::make_shared(); constraintA->Initialize(mnodeA, // node to connect truss); // Set no gravity // sys.SetGravitationalAcceleration(VNULL); // Perform a linear static analysis auto solver = chrono_types::make_shared(); sys.SetSolver(solver); solver->SetMaxIterations(40); solver->SetTolerance(1e-10); solver->EnableDiagonalPreconditioner(true); solver->SetVerbose(true); sys.DoStaticLinear(); // Output result std::cout << "poss after linear static analysis:" << std::endl; std::cout << " nodeA->pos\n" << mnodeA->GetPos(); std::cout << " nodeB->pos\n" << mnodeB->GetPos(); std::cout << "Forces after linear static analysis:" << std::endl; std::cout << " constraintA.react\n" << constraintA->GetReactionOnBody(); ``` -------------------------------- ### MKL Module - chrono::ChSolverMKL Source: https://api.projectchrono.org/development/group__mkl__module Interface to the Intel MKL Pardiso parallel sparse direct solver. This class provides access to the Intel MKL library, specifically for its parallel direct solver. Refer to the installation guide for setup details. ```APIDOC class chrono::ChSolverMKL Interface to the Intel MKL Pardiso parallel sparse direct solver. [More...](https://api.projectchrono.org/development/classchrono_1_1_ch_solver_m_k_l.html#details) ``` -------------------------------- ### Install SWIG on macOS Source: https://api.projectchrono.org/development/module_csharp_installation This command installs the SWIG wrapper generator on macOS using the Homebrew package manager, which is a requirement for building the C# module. ```bash brew install swig ``` -------------------------------- ### Chrono API Documentation - Setup Methods Source: https://api.projectchrono.org/development/functions_s This section documents the 'Setup()' method across various Project Chrono classes. It details how to initialize or configure different components of the simulation framework, including assemblies, solvers, functions, lines, loads, and systems. ```APIDOC chrono::ChAssembly::Setup() Initializes the assembly. chrono::ChDirectSolverLS::Setup() Sets up the direct linear solver. chrono::ChDirectSolverLScomplex::Setup() Sets up the direct linear solver for complex numbers. chrono::ChFunctionBSpline::Setup() Sets up the B-Spline function. chrono::ChFunctionConstJerk::Setup() Sets up the constant jerk function. chrono::ChFunctionFillet3::Setup() Sets up the 3-point fillet function. chrono::ChFunctionIntegral::Setup() Sets up the integral function. chrono::ChFunctionRotationBSpline::Setup() Sets up the B-Spline rotation function. chrono::ChFunctionRotationSQUAD::Setup() Sets up the SQUAD rotation function. chrono::ChFunctionSequence::Setup() Sets up the function sequence. chrono::ChIterativeSolverLS::Setup() Sets up the iterative linear solver. chrono::ChLineBSpline::Setup() Sets up the B-Spline line. chrono::ChLineNurbs::Setup() Sets up the NURBS line. chrono::ChLinkMotorLinearDriveline::Setup() Sets up the linear driveline motor. chrono::ChLinkMotorRotationDriveline::Setup() Sets up the rotational driveline motor. chrono::ChLoadContainer::Setup() Sets up the load container. chrono::ChPhysicsItem::Setup() Sets up the physics item. chrono::ChSolver::Setup() Sets up the solver. chrono::ChSurfaceNurbs::Setup() Sets up the NURBS surface. chrono::ChSystem::Setup() Sets up the system. chrono::ChSystemMulticore::Setup() Sets up the multicore system. chrono::ChSystemMulticoreSMC::Setup() Sets up the multicore SMC system. chrono::fea::ChMesh::Setup() Sets up the finite element mesh. chrono::industrial::TrajectoryInterpolatorJointSpace::Setup() Sets up the joint space trajectory interpolator. chrono::industrial::TrajectoryInterpolatorOperationSpace::Setup() Sets up the operation space trajectory interpolator. chrono::modal::ChModalAssembly::Setup() Sets up the modal assembly. ``` -------------------------------- ### Chrono Initialization and Visual System Setup Source: https://api.projectchrono.org/development/tutorial_demo_bricks Demonstrates how to initialize the Chrono system and set up a visualizer, supporting both Irrlicht and VSG backends. It includes setting the visualization type based on availability. ```cpp #include "chrono/physics/ChSystemNSC.h" #include "chrono/physics/ChBodyEasy.h" #include "chrono/solver/ChSolverPSOR.h" #include "chrono/assets/ChTexture.h" #include "chrono/assets/ChVisualSystem.h" #ifdef CHRONO_IRRLICHT #include "chrono_irrlicht/ChVisualSystemIrrlicht.h" using namespace chrono::irrlicht; #endif #ifdef CHRONO_VSG #include "chrono_vsg/ChVisualSystemVSG.h" using namespace chrono::vsg3d; #endif using namespace chrono; ChVisualSystem::Type vis_type = ChVisualSystem::Type::IRRLICHT; ``` -------------------------------- ### Chrono Visualization Systems Setup Source: https://api.projectchrono.org/development/tutorial_demo_stepfile Demonstrates how to set up and initialize different visualization systems (Irrlicht and VSG) within the Chrono physics engine. Includes attaching the system, setting window properties, and initializing the visualizer. ```cpp #ifdef CHRONO_IRRLICHT auto vis_irr = chrono_types::make_shared(); vis_irr->AttachSystem(&sys); vis_irr->SetWindowSize(800, 600); vis_irr->SetWindowTitle("Load a STEP model from file"); vis_irr->Initialize(); vis_irr->AddLogo(); vis_irr->AddSkyBox(); vis_irr->AddCamera([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0.2, 0.2, -0.3)); vis_irr->AddTypicalLights(); vis = vis_irr; #endif ``` ```cpp #ifdef CHRONO_VSG auto vis_vsg = chrono_types::make_shared(); vis_vsg->AttachSystem(&sys); vis_vsg->SetCameraVertical(CameraVerticalDir::Y); vis_vsg->SetWindowSize(800, 600); vis_vsg->SetWindowTitle("Load a STEP model from file"); vis_vsg->AddCamera([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0.2, 0.2, -0.3)); vis_vsg->Initialize(); vis = vis_vsg; #endif ``` -------------------------------- ### Chrono ChNodeFEAbase Setup Source: https://api.projectchrono.org/development/classchrono_1_1fea_1_1_ch_node_f_e_axyzrot-members Documentation for the SetupInitial method of chrono::fea::ChNodeFEAbase, used for system initialization. ```APIDOC chrono::fea::ChNodeFEAbase::SetupInitial(ChSystem *system) Initializes the node within the given Chrono system. ``` -------------------------------- ### Rolling and Spinning Friction Example Setup Source: https://api.projectchrono.org/development/tutorial_demo_friction This C++ code snippet demonstrates the setup for a Project Chrono simulation featuring rolling and spinning friction. It includes initializing the physics system, setting the collision system type, and creating a shared visualization material for spherical objects. ```cpp #include "chrono/physics/ChSystemNSC.h" #include "chrono/physics/ChBodyEasy.h" #include "chrono/utils/ChUtilsCreators.h" #include "chrono/core/ChRealtimeStep.h" #include "chrono/assets/ChVisualSystem.h" #ifdef CHRONO_IRRLICHT #include "chrono_irrlicht/ChVisualSystemIrrlicht.h" using namespace chrono::irrlicht; #endif #ifdef CHRONO_VSG #include "chrono_vsg/ChVisualSystemVSG.h" using namespace chrono::vsg3d; #endif using namespace chrono; ChVisualSystem::Type vis_type = ChVisualSystem::Type::VSG; int main(int argc, char* argv[]) { std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl; // Create a physical system ChSystemNSC sys; sys.SetCollisionSystemType(ChCollisionSystem::Type::BULLET); // Create all the rigid bodies. double mradius = 0.5; // Create a shared visualization material. auto sph_vis_mat = chrono_types::make_shared(); sph_vis_mat->SetKdTexture(GetChronoDataFile("textures/bluewhite.png")); ``` -------------------------------- ### TrackShoeBandANCF - Get Guide Box Dimensions Source: https://api.projectchrono.org/development/classchrono_1_1vehicle_1_1_track_shoe_band_a_n_c_f Retrieves the dimensions of the contact box for the guiding pin of the track shoe. This is an override of a virtual function. ```cpp virtual const ChVector3d & GetGuideBoxDimensions() const override; // Returns the dimensions of the contact box for the guiding pin. ``` -------------------------------- ### TrackShoeBandANCF - Get Guide Box Offset X Source: https://api.projectchrono.org/development/classchrono_1_1vehicle_1_1_track_shoe_band_a_n_c_f Retrieves the offset in the X direction for the guiding pin of the track shoe. This is an override of a virtual function. ```cpp virtual double GetGuideBoxOffsetX() const override; // Returns the offset (in X direction) of the guiding pin. ``` -------------------------------- ### Chrono Simulation Setup Source: https://api.projectchrono.org/development/tutorial_demo_motors Demonstrates basic setup for a Chrono simulation, including creating a material, a fixed floor body with visual properties, and adding it to the system. ```cpp auto material = material_data.CreateMaterial(contact_method); // Create a floor that is fixed (that is used also to represent the absolute reference) auto floorBody = chrono_types::make_shared(20, 2, 20, 3000, material); floorBody->SetPos(ChVector3d(0, -2, 0)); floorBody->SetFixed(true); floorBody->GetVisualShape(0)->SetTexture(GetChronoDataFile("textures/blue.png")); sys->Add(floorBody); ``` -------------------------------- ### ChPhysicsItem Setup and State Management Source: https://api.projectchrono.org/development/classchrono_1_1_ch_shafts_motor_speed Methods related to the setup of a ChPhysicsItem and forcing its state to rest. Also includes functions to get the number of coordinates at the velocity level and the number of constraints. ```APIDOC Setup() - Perform setup operations. ForceToRest() - Set zero speed (and zero accelerations) in state, without changing the position. GetNumCoordsVelLevel() -> unsigned int - Get the number of coordinates at the velocity level. GetNumConstraints() -> unsigned int - Get the number of scalar constraints. GetNumConstraintsUnilateral() -> unsigned int - Get the number of unilateral scalar constraints. ``` ```cpp virtual void Setup(); virtual void ForceToRest(); virtual unsigned int GetNumCoordsVelLevel(); virtual unsigned int GetNumConstraints(); virtual unsigned int GetNumConstraintsUnilateral(); ``` -------------------------------- ### ChLinkMotorLinear Methods Source: https://api.projectchrono.org/development/classchrono_1_1_ch_link_motor_linear_force-members Provides a utility to get the string representation of a guide constraint type. ```APIDOC chrono::ChLinkMotorLinear::GetGuideTypeString(GuideConstraint type) - Description: Converts a GuideConstraint enum value to its string representation. - Parameters: - type: The GuideConstraint enum value. - Returns: A string representing the guide constraint type. ``` -------------------------------- ### Chrono Simulation Setup and Visualization Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_cosimulate_load Configures the Chrono system, sets up the Irrlicht visualization, and runs the simulation loop. Includes adding cameras, enabling shadows, and rendering the scene. ```cpp auto solver = chrono_types::make_shared(); sys.SetSolver(solver); solver->SetMaxIterations(40); solver->SetTolerance(1e-10); solver->EnableDiagonalPreconditioner(true); solver->EnableWarmStart(true); sys.SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED); while (vis->Run()) { vis->BeginScene(); vis->Render(); sys.DoStepDynamics(0.005); vis->EndScene(); } ``` -------------------------------- ### Chrono System Setup and Linear Static Analysis Source: https://api.projectchrono.org/development/tutorial_demo__f_e_a_basic Demonstrates setting up a Chrono system, adding constraints, defining a solver, and performing a linear static analysis. It includes adding a truss, connecting nodes to it, and outputting node positions. ```C++ sys.[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(truss); truss->SetFixed(true); // Create a constraint between a node and the truss auto constraint1 = chrono_types::make_shared(); auto constraint2 = chrono_types::make_shared(); auto constraint3 = chrono_types::make_shared(); constraint1->Initialize(mnode1, // node truss); // body to be connected to constraint2->Initialize(mnode2, // node truss); // body to be connected to constraint3->Initialize(mnode4, // node truss); // body to be connected to sys.[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(constraint1); sys.[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(constraint2); sys.[Add](https://api.projectprojectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(constraint3); // Set no gravity // sys.SetGravitationalAcceleration(VNULL); // Perform a linear static analysis auto solver = chrono_types::make_shared(); sys.[SetSolver](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#aecf24e21d9524457a9872043b228869a)(solver); solver->SetMaxIterations(100); solver->SetTolerance(1e-12); solver->EnableDiagonalPreconditioner(true); solver->SetVerbose(true); sys.[DoStaticLinear](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a568a121e3dc9d4b5a024be9aff96c0b3)(); // Output result // std::cout <GetPos() << std::endl; std::cout << mnode2->GetPos() << std::endl; std::cout << mnode3->GetPos() << std::endl; std::cout << mnode4->GetPos() << std::endl; std::cout << "node3 displ: " << mnode3->GetPos() - mnode3->GetX0() << std::endl; ``` -------------------------------- ### ChLinkMotorLinear Methods Source: https://api.projectchrono.org/development/classchrono_1_1_ch_link_motor_linear_driveline-members Provides functionality to get the string representation of a guide constraint type for ChLinkMotorLinear. ```APIDOC GetGuideTypeString(GuideConstraint type) - Returns the string representation of the guide constraint type. - Parameters: - type: The GuideConstraint enum value. - Returns: std::string ``` -------------------------------- ### ChSurfaceNurbs Example (Conceptual C++) Source: https://api.projectchrono.org/development/classchrono_1_1_ch_surface_nurbs-members A conceptual C++ snippet demonstrating the usage of ChSurfaceNurbs setup. ```cpp #include "chrono/geometry/ChSurfaceNurbs.h" #include "chrono/geometry/ChMatrix.h" // Assuming ChVector3d and ChMatrixDynamic are defined in Chrono void ExampleNurbsSetup() { chrono::ChSurfaceNurbs nurbs_surface; int order_u = 2; int order_v = 2; chrono::ChMatrixDynamic control_points; // ... populate control_points ... nurbs_surface.Setup(order_u, order_v, control_points); // Optionally set knots and weights // chrono::ChVectorDynamic<> knots_u; // chrono::ChVectorDynamic<> knots_v; // chrono::ChMatrixDynamic<> weights; // ... populate knots and weights ... // nurbs_surface.Setup(order_u, order_v, control_points, &knots_u, &knots_v, &weights); } ``` -------------------------------- ### Project Chrono: Basic Setup and Rigid Body Dynamics (C++) Source: https://api.projectchrono.org/development/tutorial_demo_fourbar This example illustrates the fundamental steps for setting up a Chrono simulation. It includes creating a `ChSystemNSC`, adding multiple `ChBody` objects representing different mechanical components (truss, flywheel, rod, rocker), and setting their initial positions and fixed status. ```cpp int main(int argc, char* argv[]) { std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl; // 1- Create a Chrono physical system [ChSystemNSC](https://api.projectchrono.org/development/classchrono_1_1_ch_system_n_s_c.html) sys; // 2- Create the rigid bodies of the four-bar mechanical system // (a flywheel, a rod, a rocker, a truss), maybe setting // position/mass/inertias of their center of mass (COG) etc. // ..the truss auto my_body_A = chrono_types::make_shared(); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_body_A); my_body_A->SetFixed(true); // truss does not move! // ..the flywheel auto my_body_B = chrono_types::make_shared(); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_body_B); my_body_B->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0, 0, 0)); // position of COG of flywheel // ..the rod auto my_body_C = chrono_types::make_shared(); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_body_C); my_body_C->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(4, 0, 0)); // position of COG of rod // ..the rocker auto my_body_D = chrono_types::make_shared(); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_body_D); my_body_D->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(8, -4, 0)); // position of COG of rod ``` -------------------------------- ### Chrono Simulation Setup and Object Creation Source: https://api.projectchrono.org/development/tutorial_demo_tracks Demonstrates the initialization of a Chrono system, adding ground and obstacles, and setting up the Irrlicht visualization environment. It includes creating bodies with specific materials, positions, and rotations, and attaching a custom event receiver. ```C++ my_ground->GetVisualShape(0)->SetTexture([GetChronoDataFile](https://api.projectchrono.org/development/namespacechrono.html#a3bf1da4bd1bc011eeba49d5db828fd53)("textures/blue.png")); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_ground); // ..some obstacles on the ground: auto obst_mat = chrono_types::make_shared(); for (int i = 0; i < 50; i++) { auto my_obstacle = chrono_types::make_shared( 0.6 * (1 - 0.4 * ChRandom::Get()), 0.08, 0.3 * (1 - 0.4 * ChRandom::Get()), 1000, true, true, obst_mat); my_obstacle->SetMass(3); my_obstacle->SetPos([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(-6 + 6 * ChRandom::Get(), 2 + 1 * ChRandom::Get(), 6 * ChRandom::Get())); my_obstacle->SetRot([QuatFromAngleY](https://api.projectchrono.org/development/namespacechrono.html#aee13e4a7a7f53ff7dd9fef5e70cfa941)(ChRandom::Get() * CH_PI)); sys.[AddBody](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#a54c915b4322fc3ad362e19553f1fe61e)(my_obstacle); } // ..the tank (this class - see above - is a 'set' of bodies and links, automatically added at creation) MySimpleTank* mytank = new MySimpleTank(sys); // Create the Irrlicht visualization sys auto vis = chrono_types::make_shared(); vis->AttachSystem(&sys); vis->SetWindowSize(800, 600); vis->SetWindowTitle("Modeling a simplified trackjed vehicle"); vis->Initialize(); vis->AddLogo(); vis->AddSkyBox(); vis->AddCamera([ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0, 0, -6), [ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(-2, 2, 0)); vis->AddTypicalLights(); // Create some graphical-user-interface (GUI) items to show on the screen. // This requires an event receiver object. MyEventReceiver receiver(vis.get(), mytank); // note how to add the custom event receiver to the default interface: vis->AddUserEventReceiver(&receiver); ``` -------------------------------- ### Create Slider and Guide Bodies Source: https://api.projectchrono.org/development/tutorial_demo_motors A helper function to create a static 'guide' body and a dynamic 'slider' body, along with an obstacle. It simplifies the setup for linear motor demonstrations. Bodies are created using `ChBodyEasyBox` and added to the provided `ChSystem`. ```cpp void CreateSliderGuide(std::shared_ptr& guide, std::shared_ptr& slider, std::shared_ptr material, [ChSystem](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html)* sys, const [ChVector3d](https://api.projectchrono.org/development/classchrono_1_1_ch_vector3.html) mpos) { guide = chrono_types::make_shared(4, 0.3, 0.6, 1000, material); guide->SetPos(mpos); guide->SetFixed(true); sys->[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(guide); slider = chrono_types::make_shared(0.4, 0.2, 0.5, 1000, material); slider->SetPos(mpos + [ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(0, 0.3, 0)); slider->GetVisualShape(0)->SetColor([ChColor](https://api.projectchrono.org/development/classchrono_1_1_ch_color.html)(0.6f, 0.6f, 0.0f)); sys->[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(slider); auto obstacle = chrono_types::make_shared(0.4, 0.4, 0.4, 8000, material); obstacle->SetPos(mpos + [ChVector3d](https://api.projectchrono.org/development/namespacechrono.html#a5897c517250e24238a2138abb26bc31b)(1.5, 0.4, 0)); obstacle->GetVisualShape(0)->SetColor([ChColor](https://api.projectchrono.org/development/classchrono_1_1_ch_color.html)(0.2f, 0.2f, 0.2f)); sys->[Add](https://api.projectchrono.org/development/classchrono_1_1_ch_system.html#afb70a823cfc57dd9946007414bfd9f48)(obstacle); } ``` -------------------------------- ### Chrono CMake Configuration Examples Source: https://api.projectchrono.org/development/install_guides Sample CMake scripts provided within the `contrib/build-scripts` subdirectories to demonstrate how to configure Chrono. These scripts can be used as examples for satisfying dependencies for various optional Chrono modules, assuming dependencies were installed using the utility scripts. ```cmake # Example CMakeLists.txt snippet # find_package(Chrono REQUIRED) # target_link_libraries(YourTarget PRIVATE Chrono::Chrono) ``` -------------------------------- ### Chrono Physics Simulation Setup and Visualization Source: https://api.projectchrono.org/development/tutorial_demo_suspension This snippet demonstrates the initialization of a Chrono physics system, setting up the Irrlicht visualization, registering a callback for contact events, and configuring the solver. It also includes the main simulation loop. ```cpp // Use the above callback to process each contact as it is created. auto mycontact_callback = chrono_types::make_shared(); sys.RegisterAddContactCallback(mycontact_callback); // Create the Irrlicht visualization system auto vis = chrono_types::make_shared(); vis->AttachSystem(&sys); vis->SetWindowSize(800, 600); vis->SetWindowTitle("Simple vehicle suspension"); vis->Initialize(); vis->AddLogo(); vis->AddSkyBox(); vis->AddCamera(chrono::ChVector3d(0, 0, -6)); vis->AddTypicalLights(); // Create some graphical-user-interface (GUI) items to show on the screen. // This requires an event receiver object -see above. MyEventReceiver receiver(&sys, vis->GetDevice(), mycar); vis->AddUserEventReceiver(&receiver); sys.SetSolverType(chrono::ChSolver::Type::PSOR); sys.GetSolver()->AsIterative()->SetMaxIterations(20); // THE SOFT-REAL-TIME CYCLE, SHOWING THE SIMULATION // Timer for enforcing sodt real-time chrono::ChRealtimeStepTimer realtime_timer; double time_step = 0.005; while (vis->Run()) { vis->BeginScene(); vis->Render(); chrono::irrlicht::tools::drawGrid(vis.get(), 2, 2, 30, 30, chrono::ChCoordsys<>(chrono::ChVector3d(0, 0.01, 0), chrono::QuatFromAngleX(CH_PI_2)), chrono::ChColor(0.31f, 0.51f, 0.51f), true); vis->GetGUIEnvironment()->drawAll(); // .. draw the distance constraints (the massless rods) as simplified lines // .. draw the spring constraints as simplified spring helix for (auto link : sys.GetLinks()) { if (auto linkdist = std::dynamic_pointer_cast(link)) { chrono::irrlicht::tools::drawSegment(vis.get(), linkdist->GetEndPoint1Abs(), linkdist->GetEndPoint2Abs(), chrono::ChColor(0.00f, 0.08f, 0.00f), true); } else if (auto linkspring = std::dynamic_pointer_cast(link)) { chrono::irrlicht::tools::drawSpring(vis.get(), 0.03, linkspring->GetPoint1Abs(), linkspring->GetPoint2Abs(), chrono::ChColor(0.59f, 0.08f, 0.08f), 80, 10, true); } } // The torque applied to wheels, using the ChLinkMotorRotationTorque links between // wheels and truss, depends on many parameters (gear, throttle, etc): mycar->ComputeWheelTorque(); // ADVANCE SYSTEM STATE BY ONE STEP sys.DoStepDynamics(time_step); // Enforce soft real-time realtime_timer.Spin(time_step); // Irrlicht must finish drawing the frame vis->EndScene(); } if (mycar) delete mycar; return 0; ``` -------------------------------- ### Chrono Visualization System Setup Source: https://api.projectchrono.org/development/tutorial_demo_robot Configures and initializes either the Irrlicht or VSG visualization system for Project Chrono. Includes setting window properties, camera, and lights. ```cpp std::shared_ptr vis; switch (vis_type) { case ChVisualSystem::Type::IRRLICHT: { #ifdef CHRONO_IRRLICHT auto vis_irr = chrono_types::make_shared(); vis_irr->AttachSystem(&sys); vis_irr->SetWindowSize(800, 600); vis_irr->SetWindowTitle("Load a robot model from STEP file"); vis_irr->Initialize(); vis_irr->AddLogo(); vis_irr->AddSkyBox(); vis_irr->AddCamera(ChVector3d(0.2, 1.6, 3.5), ChVector3d(0, 1, 0)); vis_irr->AddTypicalLights(); vis = vis_irr; #endif break; } case ChVisualSystem::Type::VSG: { #ifdef CHRONO_VSG auto vis_vsg = chrono_types::make_shared(); vis_vsg->AttachSystem(&sys); vis_vsg->SetWindowSize(1000, 800); vis_vsg->SetCameraVertical(CameraVerticalDir::Y); vis_vsg->SetWindowTitle("Load a robot model from STEP file"); vis_vsg->AddCamera(ChVector3d(2.2, 1.6, 2.5), ChVector3d(0, 1, 0)); vis_vsg->Initialize(); vis = vis_vsg; #endif break; } } ``` -------------------------------- ### ChSystem - Get Solver Counts Source: https://api.projectchrono.org/development/classchrono_1_1_ch_system_multicore_s_m_c-members Retrieves the counts related to the solver's setup and solve operations. These are const methods. ```APIDOC GetSolverSetupCount() - Returns the number of times the solver setup was performed. - Class: chrono::ChSystem - Signature: GetSolverSetupCount() const GetSolverSolveCount() - Returns the number of times the solver was called to solve. - Class: chrono::ChSystem - Signature: GetSolverSolveCount() const ```