top of page

Software Design

fsm.jpg

Finite State Machine

Our Finite State Machine’s states are based off of locations of the board based on our diagram in the Strategy section below (see that diagram for our cardinal directions). This FSM shows a detailed description of our robot from start to finish - we didn’t succeed in implementing all of the events and actions perfectly, but in an ideal world all of this would work perfectly. Essentially, the robot will first go to the Royal Armoury, then target Winterfell first, and then Casterly Rock, and then King’s Landing, and then Dragonstone (and then all of this will repeat in the same order) while going back to the Royal Armoury to reload between each target. Targeting Winterfell and Casterly Rock share the same state (right forward corner) since we shoot at those towers from the same location (we simply change the turret angle, which is reflected in the FSM). We reach “game over” (our accepting state) whenever the 2 minutes and 10 seconds timer ends or whenever someone presses the “off” switch. At this final state, all movements cease and our robot is essentially dead, until turned on/reset again.

Movement Strategy

Our robot followed the arena walls via wall-sensing capabilities using limit switches. It stops moving when one of its 4 limit switches is pressed (i.e. robot has bumped into a wall or hits the ammo reload button in the Armoury). This strategy allows the robot to be flush against the corners of the arena before shooting so that it will have the right alignment when firing. This is especially crucial since the positions of the towers were hardcoded and not found via IR sensing, and any small inaccuracy can result the robot failing to hit the tower.

 

Additionally, we also incorporated metro timers into our software so that the robot will stop moving when the timer expires. The strategy with timers is used when shooting from the corner of the arena is not favorable, and so the robot must move to a certain position and stop in front of our target (e.g. King’s Landing), instead of being flushed against 2 walls, before it can shoot.

​

Wall Following

Picture1.jpg

This is our code to make the robot flushed to the right corner.

​

Sample Code: 

​

void rightCorner(void){

 while (!digitalRead(limitSwitchRight) == LOW){ // to move and shoot the first button

   moveRight();

 }

 

 while (!digitalRead(limitSwitchForward) == LOW){ // make flushed to wall

   moveForward();

 }

}

Buffer Back

During testing we noticed a problem when trying to move straight back from the corner to the Armoury. The robot would catch on the switch used to request ammo and fail to return to the loading area. This problem was solved by creating an additional movement pattern, called BufferBack(), whenever the robot moved to or returned from that top corner. This can be seen in the image below. A metro timer was used to have the robot move away from the switch first then move forward towards the arena corner to fire. And on the way back, it would not move straight backwards but offset itself so as to not hit the ammo switch.

Screen Shot 2019-03-14 at 8.25.35 PM.png

Sample Code:

​

void bufferBack(void){

 buffer.reset();

   while (!buffer.check()){ // this is to make sure it doesn't hit limit switch on the way back

     moveBack();

   }

 stop();

}

Targeting Strategy

Screen Shot 2019-03-14 at 8.05.12 PM.png

Since we did not have an IR sensor, we had to hardcode most of the locations into our software, and this meant that we were not able to aim at the Dragon. As mentioned in our moving strategy, we chose a corner of the arena for the robot to be flush against, and we had to test for the optimal angles that our turret servo should rotate to such that it would knock down specific towers. These angles were hardcoded (we experimented with different angles and optimized for the ones that work best with each tower).

​

Sample code:

​

//lazy susan output pin

Servo lazySusan;

int lazySusanPin = 7;

bool lego = false;

bool kingtower = false;

bool jengatower = false;

bool tower22 = false;

 

if (lego == true) {

     lazySusan.write(80);

}

else if (jengatower == true) {

     lazySusan.write(63);

}

else if (kingtower == true) {

     lazySusan.write(20);

}

else if (tower22 == true) {

     lazySusan.write(79);

}

Shooting Strategy

Our shooting strategy is very straightforward. It involves turning on the flywheel motor and opening the gate servo so that our robot can shoot balls. There is a short delay between turning on the motor and opening the gate so that the motor can reach its maximum speed before the balls roll into the flywheel chamber to be shot. When the shooting sequence is finished, the gate will close and we the flywheel motor is turned off. The flywheel motor is controlled by a MOSFET connected to the Arduino; so, turning it on or off requires changing the value written to the MOSFET. A Metro timer is set so that shooting will only occur within a certain interval of time.

Sample Code:

​

IntervalTimer myTimer;

 

void setup() {

...

myTimer.begin(interruptLoop, 130000000);

}

 

void interruptLoop() {

 stop();

 analogWrite(mosfet, 0);

 while (true) {

 }

}

​

​

© 2019 by ME 210 Team 14 - "Team-sy LC" 

    bottom of page