Hi all,
I am playing around with the motors in Project Chrono. Reading the documentation on how to control motors<https://api.projectchrono.org/motors.html#rotational_motors> states there are two main approaches which are Constraint-based approach and Load-based approach. I am trying out the Constraint-based approach using chrono::ChFunction_Setpoint<https://api.projectchrono.org/classchrono_1_1_ch_function___setpoint.html>. I got this working well with a ChLinkMotorRotationSpeed motor but when I try doing something similar to a ChLinkMotorRotationAngle I get a constant rotation speed rather than setting the motor to an angle where is am using ChFunctionRotation_setpoint in place of chrono::ChFunction_Setpoint<https://api.projectchrono.org/classchrono_1_1_ch_function___setpoint.html>. Attached is my source code. Any help would be greatly appreciated. I feel like there is something simple I am doing wrong, but I am not seeing it. Much Thanks, Richard This email is governed by the Terms and Conditions found in our Disclaimer<http://www.mi.mun.ca/ict/disclaimer>. -- You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/1e896e52074844aaa98c5da9f1a3ce69%40mi.mun.ca.
// ============================================================================= // PROJECT CHRONO - http://projectchrono.org // // Copyright (c) 2014 projectchrono.org // All rights reserved. // // 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 // http://projectchrono.org/license-chrono.txt. // // ============================================================================= // Authors: Alessandro Tasora // ============================================================================= // // Demo code about using motors to impose rotation or translation between parts // // ============================================================================= #include "chrono/core/ChQuaternion.h" #include "chrono/core/ChVector.h" #include "chrono/physics/ChSystemNSC.h" #include "chrono/physics/ChBodyEasy.h" #include "chrono/physics/ChLinkMotorRotationAngle.h" #include "chrono/physics/ChLinkMotorRotationSpeed.h" #include "chrono/physics/ChLinkMotorRotationTorque.h" #include "chrono/physics/ChLinkMotorRotationDriveline.h" #include "chrono/physics/ChLinkMotorLinearPosition.h" #include "chrono/physics/ChLinkMotorLinearSpeed.h" #include "chrono/physics/ChLinkMotorLinearForce.h" #include "chrono/physics/ChLinkMotorLinearDriveline.h" #include "chrono/physics/ChShaftsMotorSpeed.h" #include "chrono/physics/ChShaftsMotorAngle.h" #include "chrono/physics/ChShaftsPlanetary.h" #include "chrono/physics/ChShaftsGear.h" #include "chrono/core/ChRealtimeStep.h" #include "chrono/motion_functions/ChFunction_Sine.h" #include "chrono/motion_functions/ChFunctionRotation_setpoint.h" #include "chrono_irrlicht/ChVisualSystemIrrlicht.h" // Use the namespaces of Chrono using namespace chrono; using namespace chrono::irrlicht; collision::ChCollisionSystemType collision_type = collision::ChCollisionSystemType::BULLET; // Shortcut function that creates two bodies (a stator and a rotor) in a given position, // just to simplify the creation of multiple linear motors in this demo // (skip this and go to main() for the tutorial) void CreateStatorRotor(std::shared_ptr<ChBody>& stator, std::shared_ptr<ChBody>& rotor, std::shared_ptr<ChMaterialSurface> material, ChSystem& sys, const ChVector<>& mpos) { stator = chrono_types::make_shared<ChBodyEasyCylinder>(0.5, 0.1, 1000, material, collision_type); stator->SetPos(mpos); stator->SetRot(Q_from_AngAxis(CH_C_PI_2, VECT_X)); stator->SetBodyFixed(true); sys.Add(stator); rotor = chrono_types::make_shared<ChBodyEasyBox>(1, 0.1, 0.1, 1000, material, collision_type); rotor->SetPos(mpos + ChVector<>(0.5, 0, -0.15)); rotor->GetVisualShape(0)->SetColor(ChColor(0.6f, 0.6f, 0.0f)); sys.Add(rotor); } int main(int argc, char* argv[]) { GetLog() << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n"; // Create a ChronoENGINE physical system ChSystemNSC sys; sys.SetCollisionSystemType(collision_type); // Contact material shared among all objects auto material = chrono_types::make_shared<ChMaterialSurfaceNSC>(); // Create a floor that is fixed (that is used also to represent the absolute reference) auto floorBody = chrono_types::make_shared<ChBodyEasyBox>(20, 2, 20, 3000, material, collision_type); floorBody->SetPos(ChVector<>(0, -2, 0)); floorBody->SetBodyFixed(true); floorBody->GetVisualShape(0)->SetTexture(GetChronoDataFile("textures/blue.png")); sys.Add(floorBody); ChVector<> positionA3(0, 1, 0); std::shared_ptr<ChBody> stator3; std::shared_ptr<ChBody> rotor3; CreateStatorRotor(stator3, rotor3, material, sys, positionA3); // Create the motor auto rotmotor3 = chrono_types::make_shared<ChLinkMotorRotationAngle>(); // Connect the rotor and the stator and add the motor to the system: rotmotor3->Initialize(rotor3, // body A (slave) stator3, // body B (master) ChFrame<>(positionA3) // motor frame, in abs. coords ); sys.Add(rotmotor3); auto mangle3 = chrono_types::make_shared<ChFunctionRotation_setpoint>(); //mangle3->SetSetpoint(0, 0); // Create the Irrlicht visualization system auto vis = chrono_types::make_shared<ChVisualSystemIrrlicht>(); vis->AttachSystem(&sys); vis->SetWindowSize(800, 600); vis->SetWindowTitle("Motors"); vis->Initialize(); vis->AddLogo(); vis->AddSkyBox(); vis->AddCamera(ChVector<>(1, 3, -7)); vis->AddTypicalLights(); vis->AddLightWithShadow(ChVector<>(20.0, 35.0, -25.0), ChVector<>(0, 0, 0), 55, 20, 55, 35, 512, ChColor(0.6f, 0.8f, 1.0f)); vis->EnableShadows(); // Modify some setting of the physical system for the simulation, if you want sys.SetSolverType(ChSolver::Type::PSOR); sys.SetSolverMaxIterations(50); double timestep = 0.005; ChRealtimeStepTimer realtime_timer; while (vis->Run()) { vis->BeginScene(); vis->Render(); vis->EndScene(); double theta = 60*CH_C_DEG_TO_RAD; double t = sys.GetChTime(); ChQuaternion<> Sp3 = Q_from_AngAxis(theta, VECT_Z); mangle3->SetSetpoint(Sp3, t); sys.DoStepDynamics(timestep); realtime_timer.Spin(timestep); } return 0; }
