Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple hello world that involves moving a box across a straight line. #565

Open
kraftpunk97-zz opened this issue Jul 31, 2019 · 2 comments

Comments

@kraftpunk97-zz
Copy link

Hello. I studied the double pendulum example but I'm trouble understanding it, and I wanted to try something even simpler. I want to start by declaring a box and making it move a certain distance and simulate that. Is there an example detailing that or something similar?

@kraftpunk97-zz
Copy link
Author

pinging @tkoolen...

@tkoolen
Copy link
Collaborator

tkoolen commented Aug 5, 2019

OK, here's an even simpler example, tracking a sinusoidal reference trajectory for a single body moving along the y-axis, simulated using RigidBodyDynamics.simulate and animated using MeshCatMechanisms (showing the inertial ellipsoid). You'll probably want to use RigidBodySim, but I think the RigidBodySim quickstart notebook should allow you to readily adapt this example.

using RigidBodyDynamics, MeshCatMechanisms
using RigidBodyDynamics.PDControl
using LinearAlgebra

world = RigidBody{Float64}("world")
mechanism = Mechanism(world)
bodyframe = CartesianFrame3D("body")
inertia = SpatialInertia(bodyframe,
    moment_about_com=Diagonal([0.1, 0.1, 0.1]),
    com=zeros(3),
    mass=1.0)
body = RigidBody(inertia)
joint = Joint("joint", Prismatic([0.0, 1.0, 0.0]))
attach!(mechanism, world, body, joint)

visualizer = MechanismVisualizer(mechanism)
open(visualizer)

control! = let joint=joint
    function::SegmentedVector, t::Number, state::MechanismState)
        gains = PDGains(100.0, 20.0)
        q = configuration(state, joint)
        v = velocity(state, joint)
        qref = sin(t)
        vref = cos(t)
        τjoint = τ[joint]
        τjoint .= pd.(Ref(gains), q, qref, v, vref)
    end
end

state = MechanismState(mechanism)
ts, qs, vs = simulate(state, 10.0, control!, Δt=1e-1)
animate(visualizer, ts, qs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants