Big Rig (Brian B and Matt M)
Project 3 involved designing a system that would allow a "semi truck" with a trailer attached to drive in reverse without jackknifing. The first step was putting together the Lego hardware in a way that would optimize the build for this challenge. We used two large motors for the left and right front wheel power and we put them relatively close together in an effort to keep the turning radius small. We mounted the truck's sensor directly on top of the wheels facing backwards so that there would be as little friction as possible from the cable. We used a roller ball instead of rear wheels for the truck so that there would be less friction with the ground as the vehicle turned.
Because of the placement of our ev3, the truck body had to be somewhat longer than we would have liked. This proved to be a slight problem when it was time to attempt challenge 2--the extra truck length meant we were limited in how small of a turning radius the vehicle could manuever.
Challenge 1: Straight Back
Our code for the first test was simple. The vehicle would drive forwards for a short amount of time to position the trailer in line with the truck. Next, we set the gyro mode to "RATE" and then to"ANG" so that it would zero itself before backing up. We then put both motors in reverse and used a proportional control to read the gyro movement and adjust speed variables for the left and right motor accordingly. The vehicle starts at a slow speed and then speeds up to show that this system is robust at a wide range of speeds. We also kicked the trailer to demonstrate how it can react to unexpected changes in angle.
Challenge 2a: Big Circle
For part two we had to get the trailer to reverse in a circle. We added a variable theta that would get the difference between the readings from the two gyro sensors and then subtract the desired turn angle c. We would then modify the speed of each motor by that value times a proportional coefficient k, adding k*theta to the left motor and subtracting it from the right motor. This technique worked for circles with a sufficiently large turning radius.
Challenge 2b: Small Circle
When it was time to test on a smaller turning radius we had to slightly modify the code. Originally when we had the trailer driving straight back or in a large circle, the wheels would run at the same power when the desired angle was observed. This worked when the turning radius of the inner and outer wheels were sufficiently close (turning radius was on the order of meters and the distance between motors was ~2in.) But for tighter maneuvers we needed to make the left and right motors run at different speeds when the desired angle was observed.
This correction was necessary because it stabilized the equilibrium of the system. Consider a situation in which the code from Challenge 2a was used to turn around a tight circle using a reference of 25 degrees. When the difference in the gyro readings was 25 degrees, the two motors would run at the same speed. This would result in the truck driving straight back for a moment and causing the trailer to drift too far inside. In order to correct this, the truck would then have to overcompensate by straightening out. This would result in a very shaky circle or, even worse, jackknifing.
With the correction implemented in the Challenge 2b code, the outside wheel is set to run slightly faster than the outside wheel at all times. This will help keep the trailer system close to equilibrium by ensuring that the truck would drive in a circle, even without any feedback from the trailer.
In the second test of part two we changed the turning angle from 10 to 15 deg which shrunk the turning radius considerably. The change in the code from Challenge 2a to Challenge 2b can be found on line 48.
A final note
One issue we noticed for Challenge 2 that we had difficulty fixing was that, when the trailer was nudged, one motor would be instructed to run in reverse to correct the angle. This was either because the nudge was too much for the system to handle or the proportional constant was too large. We found that decreasing the constant, however, meant that the system was really unstable and could only run at low speeds. In the end, we found a set of values for angle, baseline speed, and proportional constant that worked and was somewhat robust when it came to nudging, but by no means did we have enough time to find ideal values.