Exemplo n.º 1
0
def test_programatic_robot_model():
    robot = RobotModel("robot")
    link0 = robot.add_link("link0")
    link1 = robot.add_link("link1")
    robot.add_joint("joint1", Joint.CONTINUOUS, link0, link1)
    assert(['link0', 'joint1', 'link1'] == list(robot.iter_chain()))
    link2 = robot.add_link("link2")
    robot.add_joint("joint2", Joint.CONTINUOUS, link1, link2)
    assert(['link0', 'joint1', 'link1', 'joint2', 'link2'] == list(robot.iter_chain()))
Exemplo n.º 2
0
def test_programmatic_robot_model():
    robot = RobotModel("robot")
    link0 = robot.add_link("link0")
    link1 = robot.add_link("link1")
    robot.add_joint("joint1", Joint.CONTINUOUS, link0, link1)
    assert (['link0', 'joint1', 'link1'] == list(robot.iter_chain()))
    link2 = robot.add_link("link2")
    robot.add_joint("joint2", Joint.CONTINUOUS, link1, link2)
    assert (['link0', 'joint1', 'link1', 'joint2',
             'link2'] == list(robot.iter_chain()))
    urdf = URDF.from_robot(robot)
    robot_reincarnated = RobotModel.from_urdf_string(urdf.to_string())
    assert (['link0', 'joint1', 'link1', 'joint2',
             'link2'] == list(robot_reincarnated.iter_chain()))
cylinder.transform(Translation([length / 2., 0, 0]))

# create robot
robot = RobotModel("robot", links=[], joints=[])

# add first link to robot
link0 = robot.add_link("world")

# add second link to robot
mesh = Mesh.from_shape(cylinder)
link1 = robot.add_link("link1", visual_mesh=mesh, visual_color=(0.2, 0.5, 0.6))

# add the joint between the links
axis = (0, 0, 1)
origin = Frame.worldXY()
robot.add_joint("joint1", Joint.CONTINUOUS, link0, link1, origin, axis)

# add another link
mesh = Mesh.from_shape(cylinder) # create a copy!
link2 = robot.add_link("link2", visual_mesh=mesh, visual_color=(0.5, 0.6, 0.2))

# add another joint to 'glue' the link to the chain
origin = Frame((length, 0, 0), (1, 0, 0), (0, 1, 0))
robot.add_joint("joint2", Joint.CONTINUOUS, link1, link2, origin, axis)

artist = RobotArtist(robot)

# Exercise: Update the robot's configuration
artist.update...

artist.draw_visual()
Exemplo n.º 4
0
from compas.robots import Joint

robot = RobotModel('tom')

# ==============================================================================
# Links
# ==============================================================================

base = robot.add_link('base')
shoulder = robot.add_link('shoulder')
arm = robot.add_link('arm')
forearm = robot.add_link('forearm')
wrist = robot.add_link('wrist')
hand = robot.add_link('hand')

# ==============================================================================
# Joints
# ==============================================================================

base_joint = robot.add_joint('base-shoulder', Joint.REVOLUTE, base, shoulder)
shoulder_joint = robot.add_joint('shoulder-arm', Joint.REVOLUTE, shoulder, arm)
elbow_joint = robot.add_joint('arm-forearm', Joint.REVOLUTE, arm, forearm)
wrist_joint = robot.add_joint('forearm-wrist', Joint.REVOLUTE, forearm, wrist)
hand_joint = robot.add_joint('wrist-hand', Joint.CONTINUOUS, wrist, hand)

# ==============================================================================
# Visualization
# ==============================================================================

print(robot)
Exemplo n.º 5
0
                       visual_meshes=[mesh],
                       visual_color=(0.1, 0.1, 0.1))

box = Box.from_width_height_depth(0.04, 0.3, 0.22)
box.transform(Translation.from_vector([0, 0, 0.15]))
mesh = Mesh.from_shape(box)
hand = robot.add_link('hand', visual_meshes=[mesh], visual_color=(0, 0, 1.0))

# ==============================================================================
# Joints
# ==============================================================================

base_joint = robot.add_joint('base-shoulder',
                             Joint.REVOLUTE,
                             base,
                             shoulder,
                             origin=Frame(Point(0, 0, 0), Vector(1, 0, 0),
                                          Vector(0, 1, 0)),
                             axis=Vector(0, 0, 1),
                             limit=(-0.5 * math.pi, +0.5 * math.pi))

shoulder_joint = robot.add_joint('shoulder-arm',
                                 Joint.REVOLUTE,
                                 shoulder,
                                 arm,
                                 origin=Frame(Point(0, 0,
                                                    0.5), Vector(1, 0, 0),
                                              Vector(0, 1, 0)),
                                 axis=Vector(0, 1, 0),
                                 limit=(-0.5 * math.pi, +0.5 * math.pi))

elbow_joint = robot.add_joint('arm-forearm',
Exemplo n.º 6
0
model = RobotModel('drinking_bird')

foot_1 = Box(Frame([2, .5, .25], [1, 0, 0], [0, 1, 0]), 1, 2, .5)
foot_2 = Box(Frame([-2, .5, .25], [1, 0, 0], [0, 1, 0]), 1, 2, .5)
leg_1 = Box(Frame([2, 0, 4], [1, 0, 0], [0, 1, 0]), .5, 1, 7)
leg_2 = Box(Frame([-2, 0, 4], [1, 0, 0], [0, 1, 0]), .5, 1, 7)
axis = Cylinder(Circle(Plane([0, 0, 7], [1, 0, 0]), .01), 4)
legs_link = model.add_link('legs',
                           visual_meshes=[foot_1, foot_2, leg_1, leg_2, axis])

torso = Cylinder(Circle(Plane([0, 0, 0], [0, 0, 1]), .5), 8)
torso_link = model.add_link('torso', visual_meshes=[torso])

legs_joint_origin = Frame([0, 0, 7], [1, 0, 0], [0, 1, 0])
joint_axis = Vector(1, 0, 0)
model.add_joint('torso_base_joint', Joint.CONTINUOUS, legs_link, torso_link,
                legs_joint_origin, joint_axis)

head = Sphere([0, 0, 0], 1)
beak = Cylinder(Circle(Plane([0, 1, -.3], [0, 1, 0]), .3), 1.5)
head_link = model.add_link('head', visual_meshes=[head, beak])
neck_joint_origin = Frame([0, 0, 4], [1, 0, 0], [0, 1, 0])
model.add_joint('neck_joint',
                Joint.FIXED,
                torso_link,
                head_link,
                origin=neck_joint_origin)

tail = Sphere([0, 0, 0], 1)
tail_link = model.add_link('tail', visual_meshes=[tail])
tail_joint_origin = Frame([0, 0, -4], [1, 0, 0], [0, 1, 0])
model.add_joint('tail_joint',
# create cylinder in yz plane
radius, length = 0.3, 5
cylinder = Cylinder(Circle(Plane([0, 0, 0], [1, 0, 0]), radius), length)
cylinder.transform(Translation([length / 2., 0, 0]))
mesh = Mesh.from_shape(cylinder)

# create robot
robot = RobotModel("robot", links=[], joints=[])
link0 = robot.add_link("world")

# Add all other links to robot
for count in range(1, 8):
    # add new link to robot
    robot.add_link("link" + str(count), visual_mesh=mesh.copy(), visual_color=(count * 0.72 % 1.0, count * 0.23 % 1.0 , 0.6))

    # add the joint between the last two links
    axis = (0, 0, 1)
    origin = Frame((length , 0, 0), (1, 0, 0), (0, 1, 0))
    robot.add_joint("joint" + str(count), Joint.CONTINUOUS, robot.links[-2] , robot.links[-1], origin, axis)

artist = RobotArtist(robot)
artist.clear_layer()

joint_names = robot.get_configurable_joint_names()
joint_values = [0.2] * len(joint_names)
joint_types = [Joint.CONTINUOUS] * len(joint_names)

config = Configuration(joint_values, joint_types)
artist.update(config, joint_names)
artist.draw_visual()