Hi everyone,
I'm trying to make a pendulum constraining it using a revolute joint. It
gives me no error, but it doesn't oscillate and i'm not understanding why.
Anyone might help me please?
--
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/b437474a-f802-4c93-8cc5-2b963ab78481n%40googlegroups.com.
#include "chrono/physics/ChSystemNSC.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/physics/ChLinkMate.h"
#include "chrono/assets/ChTexture.h"
#include "chrono/core/ChRealtimeStep.h"
#include "chrono/physics/ChLinkLock.h"
#include "chrono_irrlicht/ChVisualSystemIrrlicht.h"
// Use the namespace of Chrono
using namespace chrono;
using namespace chrono::irrlicht;
int main(int argc, char* argv[]) {
// Set path to Chrono data directory
SetChronoDataPath(CHRONO_DATA_DIR);
// Create a Chrono physical system
ChSystemNSC sys;
// 1 - Create a floor that is fixed (that is used also to represent the
absolute reference)
auto floorBody = std::make_shared<ChBodyEasyBox>(10, 2, 10, // x, y, z
dimensions
3000, // density
true, // create
visualization asset
false // no
collision geometry
);
floorBody->SetPos(ChVector<>(0, -2, 0));
floorBody->SetBodyFixed(true);
sys.Add(floorBody);
// 2 - Create a pendulum
auto pendulumBody = chrono_types::make_shared<ChBody>();
sys.AddBody(pendulumBody);
pendulumBody->SetIdentifier(1);
pendulumBody->SetBodyFixed(false);
pendulumBody->SetCollide(false);
pendulumBody->SetMass(1);
pendulumBody->SetInertiaXX(ChVector<>(0.2, 1, 1));
// Initial position of the pendulum (horizontal, pointing towards positive
X).
pendulumBody->SetPos(ChVector<>(0, 3, 0));
// Attach visualization assets.
auto cyl_p = chrono_types::make_shared<ChCylinderShape>(0.5, 2);
cyl_p->SetColor(ChColor(0.6f, 0, 0));
pendulumBody->AddVisualShape(cyl_p, ChFrame<>(VNULL,
Q_from_AngX(CH_C_PI_2)));
// 3 - Create a revolute joint.
auto revolute_link = chrono_types::make_shared<ChLinkLockRevolute>();
revolute_link->Initialize(floorBody,
pendulumBody,ChCoordsys<>(ChVector<>(0,3,0)));
sys.Add(revolute_link);
// Optionally, set color and/or texture for visual assets
pendulumBody->GetVisualShape(0)->SetColor(ChColor(0.2f, 0.5f, 0.25f));
floorBody->GetVisualShape(0)->SetTexture(GetChronoDataFile("textures/bluewhite.png"),
2, 2);
// 4 - Create the Irrlicht visualization system
ChVisualSystemIrrlicht vis;
vis.SetWindowSize(800, 600);
vis.SetWindowTitle("A simple project template");
vis.Initialize();
vis.AddLogo();
vis.AddSkyBox();
vis.AddTypicalLights();
vis.AddCamera(ChVector<>(2, 2, -5), ChVector<>(0, 1, 0));
vis.AttachSystem(&sys);
// 5 - Simulation loop
ChRealtimeStepTimer realtime_timer;
double step_size = 5e-3;
while (vis.Run()) {
// Render scene
vis.BeginScene();
vis.Render();
vis.EndScene();
// Perform the integration stpe
sys.DoStepDynamics(step_size);
// Spin in place to maintain soft real-time
realtime_timer.Spin(step_size);
}
return 0;
}