add 2 examples in states

This commit is contained in:
Brian Delhaisse
2019-07-01 20:00:35 +02:00
parent 62bae6117f
commit b61c612472
3 changed files with 70 additions and 4 deletions
+2 -4
View File
@@ -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
+34
View File
@@ -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)
+34
View File
@@ -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)