Problem 272336 · medium · Robotics · Level 02 Motion

Motors Until the Stops

simulation · time step · saturation · forward kinematics

A kitchen robot stirs a pot with a planar arm, its base at the origin (x right, y up). Link i has length lengths[i] and joint angle q[i] (radians, counter-clockwise). The angles are relative: q[0] is measured from the +x axis, every later one from the direction of the link before it. The hand is the end of the last link.

Each joint's motor turns at a constant speed speeds[i] (radians per second, negative means clockwise) until the joint reaches one of its stops limits[i] = (lo, hi); there it stays. The controller simulates this in steps of dt seconds. The joints start at start (inside their stops), and each step updates every joint:

q[i] = q[i] + speeds[i] * dt, then clamped into [lo, hi]

Before the robot moves, the cook wants to know where the hand ends up and how low it gets on the way (the pot's rim must stay clear). Write move_joints(lengths, start, speeds, limits, dt, steps) that runs steps steps and returns a tuple (x, y, lowest): the hand's final position, and the smallest hand height y among all steps + 1 poses, the starting pose included.

Collect the hand positions and press Run with plot(xs, ys) to see the hand's path.

Examples

Input:  lengths = [1, 1], start = [0, 0], speeds = [0.5, 1.0],
        limits = [(-3, 3), (-3, 3)], dt = 0.1, steps = 10
Output: (0.94831976, 1.47692053, 0.0)
Explanation: after 1 second the joints are at 0.5 and 1.0; the lowest
height is the start's, 0.

Input:  lengths = [1], start = [0], speeds = [-1], limits = [(-0.5, 0.5)], dt = 0.2, steps = 5
Output: (0.87758256, -0.47942554, -0.47942554)
Explanation: the joint goes to -0.2, -0.4, then would reach -0.6 but stops at -0.5,
and stays there for the last two steps.

Input:  lengths = [0.5, 0.4, 0.3], start = [1.2, -1.5, 0.0], speeds = [-0.8, 1.2, 1.5],
        limits = [(-0.2, 2.0), (-2.0, 1.0), (-1.0, 1.0)], dt = 0.05, steps = 40
Output: (0.75731682, 0.45585185, 0.2591554)
Explanation: the hand dips to 0.259 on the way and rises again.

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Simulate joints moving at constant speeds, one time step at a time
  • Clamp each joint at its stops, so it halts there
  • Track a quantity over a whole motion: the hand's lowest point
Starting Python…