# Robot JugglingÂ¶

In this assignment you will learn how to control a robot to juggle a ball. To achieve this goal, you will program a velocity controlled robot, such that it causes the ball to bounce with some desired periodic motion. Specifically, you will implement a hybrid controller that uses a mirror control law within the framework of Box 2D, a 2D physics simulator.

This assignment will be broken into the following components:

1. Robot Juggling Demo

a. Box 2D Simulator

2. PD-Control of a robot

a. Reference and Error signals

b. Implementing P-controller

c. Implementing a PD-controller

3. Robot Juggling

a. Ball Dynamics (projectile)

b. Ball dynamics with collision

c. Mirror control law

# Robot Juggling DemoÂ¶

The following code will run the instructor's solution of the juggling demo. Try not to look at the instructor's code until after completing the assignment!

To run the code, first hit the cell below. Then hit the play button from the toolbar.

In [ ]:
from tutorial import *
play_full_solution()


If a window pops up like this picture then you have successfully run the demo.

So what exactly are you looking at? As mentioned previously we are simulating the physics using Box2D.
However, the window that popped up is merely a visulazation of the simulator that uses pygame. Pygame is a software package used to create games in python. It allows the use of keyboard and mouse input. For example, if you hit 'q' or 'esc' the window should close. Note: in OS X the window may not close, however the simulation will stop.

The visulazation is showing an instance of robot juggling.

• The robot is a dark rectangular paddle.
• The ball is a magenta circle bouncing up and down
• The yellow and red horizontal bars show the desired heights.
• The upper yellow bar shows the desired peak height of the ball
• The lower red bar shows the desired impact location for the ball and the paddle.
• The ground is the green rectangle. It is a static object. Ideally your ball will never touch the ground!

### Reference framesÂ¶

All of the objects has a local reference frame located in the center of its body.

Our fixed frame is an interial reference frame with $\hat{x}$ increasing to the right and $\hat{y}$ increasing upwards.

### SimulationÂ¶

All of the objects listed above are rigid bodies that (approximately) obey the laws of physics $\vec{F} = m \vec{a}$. By definition, rigid bodies are not able to penetrate one another.

For every discrete time step, Box2D will attempt to tell us the state (position, velocity, and acceleration) of each body in our domain. During the time step, Box2D will integrate the state of the objects (based on the forces applied). Then, if the state of the objects are in conflict (e.g: overlapping geometry) it will try to resolve the penetration error. The following article goes into more depth about the simulation.

For our purpose, it's important to know that the physics simulator will approximate the state of the world and can have errors in numerical accuracy.