Swamp Fox: By Sahana and Alex


Swamp Fox, or at least that's her call sign when she speaks over her favorite trucker radio frequency, has implemented gyro sensors into her truck and trailer in order to better control her orientation when backing up and driving.

The cab of Swamp Fox's truck was constructed very similarly to the ultrasonic car of project 1, with one small deviation -- a pin on the back that allows the trailer to connect to one point on the cab, becoming a full fledged tractor trailer. This design features two gyro sensors: one on the trailer bed and one on the cab. We only used the values from one gyro sensor (on trailer bed) for part 1 but in part 2, we used the values from both the sensors to control our system.

The first part of this project was to have the truck move backwards in a straight line. Using proportional control, the truck would adjust itself when its path skewed off a straight line. Our initial approach was simple--when the gyro sensor detected that the trailer was going off course, have one wheel speed up and the other slow down accordingly to return to proper orientation. In practice, this was much harder than anticipated, and required implementation of various "if" and "elif" statements.

First, we saw that even tiny changes in the orientation of the trailer bed, when multiplied by Kp and applied to the speed of each wheel, eventually compounded and made the difference in wheel speeds too great. To combat this we decided that, while our goal was of course to have the sensor read 0 degrees, we would not have the wheels change speeds unless the trailer was off by more than 3 degrees. This actually gave the trailer a bit more flexibility, and more time to right itself as it approached the desired orientation.

Second, we saw that if the angle of offset became too great, it became extremely difficult for the motors to overcome the mass of the truck and its momentum. Additionally, due to our control equation, the motors moved at very high speeds. This was very hard to recover from. We decided to instill an "anglelimit" variable. When the gyro sensor sensed that it was at an angle greater than the allowed "anglelimit," the speeds of the motors would become constant. This allowed for much more control and better recovery after catastrophic collisions.

Last, we realized that we needed the motors to behave differently based on whether or not the angle of offset was getting worse, or actually improving. This brings us to the if statements inside the "else" statement at the end of the code. If the reading on the gyro sensor is increasing, one wheel gets faster and the other gets slower to try and reorient the trailer. Once the gyro reading begins to decrease, indicating that the trailer is righting itself, the wheels switch - the one that was speeding up now slowed down, and vice versa. This helped the truck better ease into the correct orientation.

In the end, we were successful in getting the truck to repeatedly reorient itself when its path was interrupted, and eventually return to a straight path. You can see that while it is slow going, each time the truck over corrects itself, it is by a smaller and smaller margin, until finally the truck is pretty much going straight in its original direction, showing a successful implementation of proportional control.

The second part involved the truck travelling in a curved path, that it would return to if there was noise in the system. Given the work in part 1, it was very easy to write this code. First, there is a while loop which involves the car pivoting along one wheel in order to get to the desired orientation between the two gyro sensors. Then, it was as simple as replacing the single angle measurement in part 1 with a comparison of both of the gyro sensor readings. You can see in the video that the motion is a bit choppy and this is due to friction with the floor and the inherent instability in the trailer. But it is also evident that the truck is continuously fixing itself as the trailer goes askew, and then returning to the circular path, even when the trailer is hit with an external force.

In the end, Swamp Fox was successful in righting itself to follow a straight path as it backs up, and righting itself to follow a curved or circular path, using proportional control.



Front view of Swamp Fox, showing the connections between the motors and the brick.


Pin set up that connects the trailer to the cab.


How the two gyro sensors are affixed and connected to the brick.


Full side view of Swamp Fox. She is magnificent.


Swamp Fox moving backwards in a straight line

Swamp Fox readjusting itself if there is a "obstruction"

Swamp Fox moving around in a circle (small)

Swamp Fox moving around in a circle (big)


Part 1: Code for Swamp Fox to back up

Image Image

Part 2: Code to have Swamp Fox move in a small circle

Image Image Image