The Layers of Our Program


Lowest Level:My Blocks

We modularized our program into three different levels for consistency, ease of programming, and organization. The lowest level of our programs are the My Blocks. My Blocks are blocks that you can program yourself to do a function using the standard libraries. There are 6 total libraries, actions, flow control, sensors, data operations, advanced, and My Blocks. Some of the action blocks do not perform well on our robot because of certain factors such as the friction on the wheels, the weight of our robot, the varying motor performance, and other engineering factors. To accommodate for this, we designed our own action blocks that work better for our robot. We have 6 My Blocks as described below.

MoveStraight_DOR: 
                                             




DOR stands for degrees of rotation. There are three inputs that this My Block takes: power, steering gain, and degrees of rotation. We have three parts in this program, direction, drift correction, and DOR. First we refer to the power input to check whether our robot should move forwards or backwards. Then in a loop we check the gyro to make sure that we are moving straight, if not then we find the opposite of the current angle that the robot is at and scale by the steering gain before turning that amount using move steering. This ensures that we are always moving straight. Next we find the average of the two drive motor rotations and check if we have reached the target number of degrees that we have to move forward. If we have then we exit the loop, if not we repeat the loop. Once we exit the loop we simply turn off the motors.

MoveStraight_SOL:




SOL stands for stop on line. This block takes 4 inputs: power, steering gain, stop on line color, and condition. Like in MoveStraight_DOR, we first check the power to see whether our robot should move forwards or backwards. Then in a loop we check the gyro to make sure that we are moving straight, if not then we find the opposite of the current angle that the robot is at and scale by the steering gain before turning that amount using move steering. Next we check the color sensor to see if it has sensed the type of color line our input says we are trying to find. Because we have two color sensors we have two conditions, "or" which means the robot will stop when one of the color sensors see the black line and "and" which means the robot will only stop when both color sensors see the line. We check if the color sensor(s) that have seen the line satisfy this condition. If true, then we exit the loop, if false, we repeat the loop. After we exit the loop, we simply stop the robot.

AntistallMediumMotor:





Antistall is an algorithm where if the motor gets stuck, instead of just waiting for the motor to turn the amount of degrees it should(which will take literally forever), it will stop and move on after a certain amount of time. This block has three inputs: degrees to turn this motor, power, and the timer. During this block we simply operate a turn on our medium motor(the smallest type of motor) and if it doesn't finish its turn before the timer runs out them we stop the turn.

AntistallLargeMotor




Antistall is an algorithm where if the motor gets stuck, instead of just waiting for the motor to turn the amount of degrees it should(which will take literally forever), it will stop and move on after a certain amount of time. This block has three inputs: degrees to turn this motor, power, and the timer. During this block we simply operate a turn on our large motor(the largest type of motor) and if it doesn't finish its turn before the timer runs out them we stop the turn.

GyroTurn




Gyro Turn has 4 inputs: degrees of turning, sharpness, timeout, and turn scale. First we tell whether we are turning right or left based on whether the angle that we turn is positive or negative.(- =left and + =right) Then we use the difference between how much we have turned and how much we have to turn to decelerate as we complete the turn. If we need to magnify the power we use the turn scale. Sometimes the robot decelerates to early and we get stuck trying to finish the turn. That's why we use a timeout to just move on if we don't completely finish our turn.

StopAllMotors

We use this block at the end of every task. It simply turns off all motors.

Task Level:

 The next layer consists of tasks. A task is a combination of missions that can be accomplished together before the robot returns back to base.  This level of our program consists of only Flow Control blocks and My Blocks. We created 5 tasks:

T1_TMIEV 
In this task we complete the missions:
-Escape Velocity
-Tube Module Insertion

T2_STSA
In this task we complete the missions:
-Space Travel Ramp
-Solar Array

T3_E
In this task we complete the missions:
-Extraction

T4_3DPMDCC
In this task we complete the missions:
-3D printer, Meteorite Deflection
-Crater Crossing 

T5_FOABDS
In this task we complete the missions:
-Food Processor
-Observatory
-Aerobic Exercise
-Brick Drop
-Move one satellite to outer orbit

Final Level:

Now that we had the building blocks for our robot game, we simply strung it together into one final program. Using each task as a My Block in Switch (Flow Control) block we determined which brick button was pressed. Each button executed a certain task. We then put this in a loop so that we could rerun any tasks at any time during the robot game.

Comments