Move to joint targetsΒΆ

Offset all joints from their current positions, then move to a named joint state declared by the robot model.

from olo import Client
from olo.kinematics import JointTarget

JOINT_OFFSET = 0.3

with Client() as client:
    robot = client.robot()
    arm = robot.kinematics

    joints = arm.joints()
    group = arm.model.group()

    # Offset all arm joints from their current positions.
    positions = [position + JOINT_OFFSET for position in joints.positions]
    arm.move_joints(
        JointTarget(names=joints.names, positions=tuple(positions)),
    )

    # Move to a named joint state from the robot model.
    named_state = next(
        (state for state in group.group_states if state.name in {"home", "ready"}),
        group.group_states[0],
    )
    print(f"Moving {group.name} to named state {named_state.name!r}")
    arm.move_joints(named_state.joints)
import { JointTarget, groupState } from "olo/kinematics";
import { connect } from "olo/web";

const JOINT_OFFSET = 0.3;

const client = connect();
const robot = await client.robot();
const arm = robot.kinematics;

const joints = await arm.joints();
const group = (await arm.getModel()).group();

// Offset all arm joints from their current positions.
const positions = joints.positions.map((position) => position + JOINT_OFFSET);
await arm.moveJoints(
  new JointTarget({
    names: joints.names,
    positions,
  }),
);

// Move to a named joint state from the robot model.
const namedStateName =
  group.groupStates.find((state) => state.name === "home" || state.name === "ready")?.name ??
  group.groupStates[0]!.name;
const namedState = groupState(group, namedStateName);
console.log(`Moving ${group.name} to named state ${JSON.stringify(namedState.name)}`);
await arm.moveJoints(namedState.joints);