Skip to content

Robot control & MDPs

Mathematical representation of robot motion

Section titled “Mathematical representation of robot motion”

Robots come in a wide variety of morphologies. How can we control them? We assume robots are rigid bodies and robot motion can be represented as rigid-body motion. Rigid body means that any two points on the robot maintain a constant distance. As such, we only have to track one point on the robot instead of multiple.

Robot motion

To represent robot motion mathematically or in code, we use homogeneous transformation matrices.

SE(2): 3 degrees of freedom

SE(3): 6 degrees of freedom

In order for these to be valid rotation matrices, they must satisfy the following properties:

  1. The matrices must be orthogonal, meaning that the transpose of the matrix is equal to its inverse.
  2. The determinant of the rotation matrix must be equal to 1, which ensures that it represents a proper rotation without any scaling or reflection.

Why do we care about these rotation matrices? It’s so that we can chain transformations together to determine an object’s position in the base frame given its position in some sensor’s frame.

Chaining transforms

However, robot is not a single solid body. Most humanoids have links (rigid parts) that are connected by joints (which allow for relative motion between the links), and end effectors (which are the parts of the robot that interact with the environment, such as hands or grippers). To find out the position of the end effector in the base frame, we can apply the transform chaining technique above.

For robot arms, Franka is a typical example of a 7 degree of freedom robot arm.

Robot arms

For effectors, suction grippers, parallel grippers, and dexterous hands are common types.

Robot effectors

Hard-coded geometry vs learned representations

Section titled “Hard-coded geometry vs learned representations”

Intuition: Motion planning in C-space quickly becomes intractable as the number of degrees of freedom increases. In modern robot learning, we don’t want to have perfect world information, we want to learn a policy that can learn to feel where the obstacles are implicitly and recognizing automatically invalid states.

Task space: the manifold in which the robot’s task is naturally defined, independent of its embodiment. If task space dimension is less than the robot’s degree of freedom, then the robot is redundant. If task space dimension is greater than the robot’s degree of freedom, then the robot is underactuated.

Example: task is whiteboard cleaning, task space is whiteboard surface .

Example: Franka’s arm C-space, workspace, and task space

Franka robot

Example of redundancy leading to null space motion: a Franka arm holding a cup of coffee can move its elbow without affecting the position of the cup. This is called null space motion, and it can be used to optimize for secondary objectives such as avoiding obstacles or minimizing energy consumption.

Forward kinematics: given the robot’s joint angles, compute the position of the end effector in the base frame. This process is straightforward and can be done by chaining together the transformations from the base frame to the end effector frame.

  • Maps from C-space to task space,
  • Deterministic, but not bijective (multiple joint configurations can lead to the same end effector position).

Inverse kinematics: given the desired position of the end effector in the base frame, compute the joint angles that will achieve that position. This is much harder as there might be multiple configurations to achieve the same end effector pose.

  • , mapping
  • Often non-unique or has no analytical solution
  • Optimization-based inverse kinematics (IKs): introduce cost function (how far away current end effector pose is from target pose), add some secondary constraint (obstacle, energy), and optimize for the joint angles that minimize cost with gradient descent.

Objective: Minimize the distance between the current end effector pose and the target pose.

Loss:

Update:

Gradient of the loss w.r.t. the joint angles:

where is the Jacobian matrix of the forward kinematics function with respect to the joint angles .

Jacobian method:

The problem: Near a singularity, the Jacobian loses rank and the simple update can blow up with enormous joint velocities. To avoid this, we add a damped term to the update.

Plain gradient descent uses as a rough stand-in for . DLS derives a better update by solving an explicit optimization over . The idea: find the joint velocity such that , but also penalize large :

Take derivative w.r.t. and set to zero:

IK only gives the target joints, but robot cannot jump there. To convert IK to motor commands, we need to take into account the time of movement. For this, we generate tiny waypoints along the path so the robot can follow them.

  • Inputs: , time , and control frequency
  • Number of waypoints: (one waypoint = one movement command)
  • Normalized time progress:
  • Waypoints:

However, many issues with LERP:

LERP issues

Thus, most controllers use quintic splines, a polynomial-based method, to generate waypoints, i.e., representing the trajectory of each joint as a 5th order polynomial.

  • Then add 6x boundary conditions for smoothness:
    • Start and end with no velocity and acceleration, while keeping position
  • Quintic time scaling:
  • Standard for industry robots like Frankas

Quintic splines

In the real world, the robot would not follow these waypoints perfectly because of friction and air resistance. Thus, we need to use PID controllers. The difference between the desired joint angles and the current joint angles (the tracking error) is fed into a PID controller. The controller calculates the appropriate control signal.

Given trajectory waypoints and current measurement, continuously calculate corrective motor commands ().

Tracking error:

Continuous form:

Discrete form:

PID control

Representing a policy

Not too different from an image classifier, the policy takes in an observation and outputs an action conditioned on the observation and outputs a distribution over actions.

Some environments are only partially observable, so (state, fully observable) becomes (observation, partially observable). is the action taken at time , and is the policy, which is a conditional probability distribution over actions given the observation, parameterized by the neural network weights, .

Markov property

MDP

  • State space can be discrete (chess, go) or continuous (robot movement)
  • Similarly, action can be discrete (play a certain card from 64, keyboard WASD) or continuous (apply force in x, y, z direction)
  • Transition model can be deterministic or stochastic . Uncertainty caused by sensor noise, motor overshooting, i.e., latent variables
  • Reward function can be sparse (reward only at the end of the episode) or dense (reward at every step). E.g., robot arm trying to pick up a cup, reward only when it successfully picks up the cup (sparse), or reward based on how close the end effector is to the cup (dense).

How likely a trajectory is under a policy and transition model .

Trajectory probability

  • Finite-horizon MDPs: the episode ends after a fixed number of steps .
  • Infinite-horizon MDPs: the episode can go on indefinitely, and we introduce a discount factor to ensure that the total reward is finite so the robot doesn’t just keep trying to maximize reward forever without ever stopping.

The optimal policy is the one that maximizes the expected return, which is the sum of discounted rewards over time. We can’t straight up use total reward because the world is stochastic, so we need to take the expectation over all possible trajectories that could occur under the policy.

Learning objective