The Bump Bot Clutter Counter is an autonomous, self balancing bot that traverses the room while playing "The Clean Up Song". Its limit switches are triggered when it hits an obstacle or something that is causing "clutter" in the room. Then, it backs up, pivots, and continues traversing while keeping track of the number of things it has hit. At the end of a designated run time, the bot stops playing "The Clean Up Song" and beeps a consecutive amount of beeps that corresponds to the number of objects it has hit.
The base of the system operates on Lab 6.4 of Dr. Daniel Block's ME461 class where we were required to use the boards accelerometers, gyros, and motors to form a closed loop algorithm to let the bot balance itself while accepting inputs for moving forward, backward, and turning. The main revisions I made to my previous lab assignment come from the use of a "bumpState" variable to determine if the bot has hit something, and the use of "EPwm9Regs.TBPRD = song[song_counter]" to play a song on the included "buzzer".
The bumpState implementation is below:
FwdBackOffset = -0.75; //offset so the bot moves forward by default
if(bumpState == 0)
{
FwdBackOffset = -0.75;
if (GpioDataRegs.GPDDAT.bit.GPIO122 == 0)//if push button one is pressed
{
bumpCounter++; //indexes counter variable that tracks # of bumps.
bumpState = 10; //cause the bot to start its revese sequence
reverseTimer = 0;//starts the timer for reversing at 0
}
}else if(bumpState == 10){
FwdBackOffset = 0.75; // causes the bot to move backwards
reverseTimer++; //indexes the counter used as a timer for reversing
if(reverseTimer>1000){
bumpState = 20; //send to turn state
reverseTimer = 0; //starts the reverse timer at 0;
spinTimer = 0; //starts the spin timer at 0;
}
}
else if(bumpState == 20){
FwdBackOffset = 0; //stops the bot from moving forward or back
turnrate = 2; // sets the rotation rate
spinTimer++; //indexes the counter used as a timer for reversing
if(spinTimer>1000){
turnrate = 0; //stops the bot from rotating
FwdBackOffset = -0.25;// go forwards
bumpState = 0; //returns bump state to 0 (signifies no bump)
spinTimer = 0; //reset spin timer for next time
}
}
First, the bot is assigned a negative "FwdBackOffset " to move forward by default, as the orientation of my bot is technically reversed from the way I programmed it for lab 6.4. By default, bumpState is set to 0. Here, gpio122 is checked. If its condition is "0" this signifies a closed circuit, and that one (or both) of the two limit switches wired in parallel to ground has been triggered. This signifies a bump of the bot. If this occurs, the bumpCounter is incremented to keep track of the number of bumps, and the reverseTimer variable is started at 0. bumpState is then set to 10 to initiate the reverse commands. This is read by the "if (bumpState == 10)" command, and changes the 'FwdBackOffset" to cause the bot to reverse. Next, the reverseTimer variable is incremented, and an if statement is used to check if it has reversed for 1000 calls of the timer 2 interrupt. Once this occurs, the reverseTimer counter variable and spinTimer counter variable are zero'd, and bumpState 20 is called to initiate the rotate sequence. This operates in the same manner that the reverse sequence does, but it sets the "FwdBackOffset" = 0 to stop moving forward or back, and it sets the "turnrate" = 2 to initiate rotation. Finally, all counter variables are zero'd, and bumpState is set back to 0 to signify that it is no longer recovering from a bump.
Next, a song was played using the following implementation:
Each note was defined by its carrier frequency. I do not know very much about music, and I have my good friend and fellow student, Ryan Siu, to thank for these not definitions:
#define C4 (50000000.0 / (261.63 * 2))
#define Db4 (50000000.0 / (277.18 * 2))
#define D4 (50000000.0 / (293.66 * 2))
#define Eb4 (50000000.0 / (311.13 * 2))
#define E4 (50000000.0 / (329.63 * 2))
#define F4 (50000000.0 / (349.23 * 2))
#define Gb4 (50000000.0 / (369.99 * 2))
#define G4 (50000000.0 / (392.00 * 2))
#define Ab4 (50000000.0 / (415.30 * 2))
#define A4 (50000000.0 / (440.00 * 2))
#define Bb4 (50000000.0 / (466.16 * 2))
#define B4 (50000000.0 / (493.88 * 2))
#define C5 (50000000.0 / (523.25 * 2))
#define Db5 (50000000.0 / (554.36 * 2))
#define D5 (50000000.0 / (587.32 * 2))
#define Eb5 (50000000.0 / (622.26 * 2))
#define E5 (50000000.0 / (659.26 * 2))
#define F5 (50000000.0 / (698.46 * 2))
#define G5 (50000000.0 / (783.99 * 2))
#define Ab5 (50000000.0 / (830.61 * 2))
#define A5 (50000000.0 / (880.00 * 2))
Next, I defined a matrix containing all of the notes of the song I wanted to play as well as a counter variable for indexing through the notes. Note all of the "0" entries that serve as a pause between notes. I must also add that I had intended on making the bot play the "Barney and Friends Cleanup Song", but struggled to find the sheet music for it, and decided to go with the melody of "Twinkle Twinkle Little Star" as there are some cleanup songs that can be sang to the same melody.
#define SizeOfSong 48
float song[SizeOfSong]={A4, 0.0, A4, 0.0, G5, G5, G5, 0.0, //array containing each note for song
A5, 0.0, A5, 0.0, G5, G5, G5, 0.0, //0.0 added to "disconnect" notes so there is a gap in each note
G5, 0.0, G5, 0.0, F5, 0.0, F5, 0.0,
E5, 0.0, E5, 0.0, D5, D5, D5, 0.0,
G5, 0.0, G5, 0.0, F5, 0.0, F5, 0.0,
E5, 0.0, E5, 0.0, D5, D5, D5, 0.0
};
uint16_t song_counter = 0;
In order to play the song, an if statement checks the value of the song counter variable. This variable starts at 0, plays the first note the first time the timer 2 interrupt is called, and then incremented. The next time the if statement is called, it plays the next indexed note, so long as it does not exceed the size of the matrix containing notes.
To play the bump beeps at the end, an if statement was used to check the condition of "runTimer". This variable served as a counter for the amount of times that the timer 2 interrupt was called, and works to end the counting of bumps. From there, a decBumpCounter is set equal to the number of bumps, and is decremented each time a buzz is called. It is not decremented when a pause is played. This allows the bot to end its duty by buzzing one time for each thing it bumped into during its preset run time determined by runTimer.
Comments
Please log in or sign up to comment.