Ball and Beam
By
Linus Wong & David Johnson
Spring 2003 Mechatronics



Introduction:
     For this project, a ball is allowed to roll along the track of a beam that is pivoted at the center. The problem involves holding a steady position and moving the ball from one position on the track to another by controlling the track angle. A camera and motor encoders are used as the systems sensors and a DSP (TI's C6711) is used to determine the control effort.

Design | The Camera | Control | Multimedia | Code

Design:
     We used an aluminum track as our beam. This track was covered in black electrical tape so that the camera would be able to easily threshold the image data and distinguish the ball from the track.
     The track was mounted to a motor at its center. The motor received its commands from the DSP through a PWM board.
     The Camera is attached to a board that is placed on top of the DSP boards. This camera was set to send frames at 12.5 Hz.

The Camera:
     The image data received from the camera showed more than just the beam, so the first step was to determine the region of interest. Because the camera was mounted, this region of intereset was simply hard coded (A copy of the raw image with bounding box over the region of interest is shown below).


     The image of the track was thresholded, and the resulting black and white area was analyzed to determine the centroid of the ball (the average column of the white space). This centroid was used to determine the coordinates of the ball with respect to the center of the track.

Control Loops:
     We originally planned to use a state space model to control the ball and beam system. However, because we could only receive data on the balls position at 12.5 Hz (we could receive the bars position much more frequently, giving us two unique sample rates) we decided to use a pair of control loops as seen below.


     The X-controller used a PID control scheme to provide a reference angle for the bar controller. This controller took form as the following line of code.

     theta_ref = Kp_ball*(ball_error) + Ki_ball*int_ball - Kd_ball*ball_dot;

     Before this signal was sent to the theta-controller, the theta_ref value was saturated at 0.1 radians with the following code. This was done to prevent the ball from moving too quickly for the camera to follow it.

     if (fabsf(theta_r) > angle_sat) {
       theta_r = angle_sat*theta_r/fabsf(theta_r);
     }

     The theta-controller also used a PID control scheme, which can be seen in the following line of code.

     u = Kp_angle*(angle_error) + Ki_angle*int_angle + Kd_angle*angular_velocity;

Pictures and Video:
Video
     The link below will bring up a 15 second video of our system running (please pardon our shaky hands). The video starts with an overview of our setup. The camera zooms in on the actual ball and beam portion, and finally moves up to see the oscilloscope. More details about each of these can be found below with the corresponding pictures.

Click here
for our
15 Second Video

Picture of Ball & Beam
     The following picture shows just the ball, beam, and motor. The ball is a typical mouse ball. The beam has been taped over with black electrical tape, and stoppers have been added to the ends of the beam to keep the ball in the camera's view.

Picture of The Overhead-Camera
     This picture shows the camera that was used to detect the ball's position and velocity. This camera was mounted over the ball and beam.

Picture of The LCD & DSP Board
     This picture shows the LCD screen that was attached to the DSP. The first line displays the dipswitch settings, and the corresponding r_ref (currently zero), and the second line is the control effort and the ball position (in meters).

Picture of The Oscilloscope
     The top line on the oscilloscope is the control effort being given to the motors. The second line is the ball position according to the camera.

Code:
Ball and Beam code
Lab 9 code w/ VB