From b61c61247218695d3f6619b7a342f32b35d7a8ec Mon Sep 17 00:00:00 2001 From: Brian Delhaisse Date: Mon, 1 Jul 2019 20:00:35 +0200 Subject: [PATCH] add 2 examples in states --- examples/states/README.rst | 6 ++---- examples/states/robot.py | 34 ++++++++++++++++++++++++++++++++++ examples/states/world.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 examples/states/robot.py create mode 100644 examples/states/world.py diff --git a/examples/states/README.rst b/examples/states/README.rst index 2cb30e6..3899807 100644 --- a/examples/states/README.rst +++ b/examples/states/README.rst @@ -15,10 +15,8 @@ States can also be given to dynamical models (which predicts the next state give Here are few examples that you can find in this folder: 1. ``basics.py``: demonstrate the various features of the ``State`` class. -2. ``robot.py``: get the joint states of a specific robot and print them. -3. ``world.py``: get the pose state of an object loaded in the world. -4. ``sensor.py``: get the state of a sensor. -5. ``interface.py``: get the state from a game controller interface. +2. ``world.py``: get the pose state of an object loaded in the world. +3. ``robot.py``: get the joint states of a specific robot and print them. Simple Example diff --git a/examples/states/robot.py b/examples/states/robot.py new file mode 100644 index 0000000..1d25ac4 --- /dev/null +++ b/examples/states/robot.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +"""Get the robot's joint position and velocity states. + +In this example, we load a Kuka manipulator and print the joint position and velocity states. You can try to move the +robot and see how it affects the states. +""" + +from itertools import count +import pyrobolearn as prl + + +# Create simulator +sim = prl.simulators.Bullet() + +# create world +world = prl.worlds.BasicWorld(sim) + +# load the kuka robot +robot = world.load_robot('kuka_iiwa') + +# create joint states +state = prl.states.JointPositionState(robot, joint_ids=[1, 2]) + prl.states.JointVelocityState(robot, joint_ids=1) + +# perform simulation +for t in count(): + + # update the state + state() # or state.read() + + # print the state + print(state) + + # step in simulation + world.step(sleep_dt=sim.dt) diff --git a/examples/states/world.py b/examples/states/world.py new file mode 100644 index 0000000..91757b2 --- /dev/null +++ b/examples/states/world.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +"""Get the cartesian position state of an object loaded in the world. + +In this example, we load a sphere in the world which can be moved using the mouse. At every time step, we print the +cartesian position state of the sphere. +""" + +from itertools import count +import pyrobolearn as prl + + +# Create simulator +sim = prl.simulators.Bullet() + +# create world +world = prl.worlds.BasicWorld(sim) + +# load a sphere in the world +sphere = world.load_sphere(position=(0., 0., 1.), mass=1., radius=0.2, color=(0.8, 0, 0, 1.), return_body=True) + +# create state +state = prl.states.PositionState(sphere) + +# perform simulation +for t in count(): + + # update the state + state() # or state.read() + + # print the state + print(state) + + # step in simulation + world.step(sleep_dt=sim.dt)