Division D: Coding Archive

Overview:

Division D’s programming philosophy embodies an efficient state machine relying on feedback loops to ensure maximum repeatability. As a result, the AEV currently relies on reflectance sensors to track it’s absolute position throughout the run, as opposed to a time-based approach. Using variables allows for flexibility accounting for track variance and battery power. (To view the vocabulary for Arduino coding go to AEV controller glossary.)

Preliminary R&D

Scenario 1

The following code was programmed so that the group could become familiar with the language. The Arduino Nano was wired to a system including a battery and two motors attached to propellers. The motors were used to detect resistance to the motion of the propellers. The system was used purely as an education experience as the AEV program did not perform a test run.

 // Accelerate motor 1 from 0 to 15 in 2.5 sec
 celerate(1,0,15,2.5)
// Run motor 1 at 15 for 1 sec
 motorspeed(1,15,1)
 goFor(1)
 // Brake 1
 brake(1)
 // Accelerate motor 2 from 0 to 27 in 4 sec
 celerate(2,0,27,4)
 // Run motor 2 for 27 for 2.7 sec
 motorspeed(2,27)
 goFor(2.7
 // Deccelerate motor 2 from 27 to 15 in 1 sec
 celerate(2,27,15,2)
 // Brake 2
 brake(2)
 // Reverse 2
 reverse(2)
 // Accelerate all from 0 to 31 in 2 sec
 celerate(4,0,31,2)
 // Run all motors at 35 for 1 sec
 motorspeed(4,35)
 goFor(1)
 // Brake 2
 brake(2)
 // Run motor 1 at 35 for 3 sec
 motorspeed(1,35)
 goFor(3)
 // Brake (4)
 brake(4)
 goFor(1)
 // Reverse 1
 reverse(1)
 // Accelerate 1 from 0 to 19 for 2 sec
 celerate(1,0,19,2)
 // Run motor 2 at 35 and 1 for 19 for 2 sec
 motorspeed(2,35)
 motorspeed(1,19)
 goFor(2)
 // Run all at 19 for 2 sec
 motorspeed(4,19)
 goFor(2)
 // Deccelerate all to 0 in 3 sec
 celerate(4,19,0,3)
 // Brake all
 brake(4)

Scenario 2:

The following code functioned as test for the reflectance sensors. The code starts by running all the motors at 25 percent power so that momentum is built. Then, power is decreased by five percent until the AEV reaches an absolute position (the specifics of this program are located in AEV controller glossary). After wards, all motors are reversed and the motor speed is increased by ten for 1.5 seconds. The program ends by braking all motors.

// Run all at 25 for 2 sec
 motorspeed(4,25)
 goFor(2)
// Run all at 20 for 12 ft
 motorspeed(4,20)
 goToAbsolutePosition(295.4)
// Reverse all
 reverse(4)
// Run all for 30 for 1.5 sec
 motorspeed(4,30)
 goFor(1.5)
// Brake all
 brake(4)

Data Analysis Tool

The following code tested the energy used age of the current AEV. The AEV performed this on the desktop stand so that Division D could understand the baseline for energy consumption. Using a track which has variance affects the energy of the system. The code starts with increasing the power usage from 0 to 100 in 5 seconds. Next, the motor continues at 100 percent for 5 more seconds. The graph for energy over time can be viewed on the data analysis tool page.

//Increase motor one battery power from 0 to 100 in 5 seconds
celerate(1, 0, 100, 5); 
//Continue motor speed for 5 seconds
motorSpeed(1, 100); 
goFor(5);

Advanced R&D 1,2

The following code functioned as a test for the stopping distance of prototype 1. It was the first time Division D’s AEV had performed on the monorail track. The code started at a specific position on the track and increased the battery power from 0 to 40 percent. After the vehicle traveled sixteen feet, the motor shut off. The AEV’s coasting distance was then measured.  To view the design for prototype 1, see design evolution; to view the blue prints for prototype 1 as orthographic projections by the team members, see creative design thinking.

Coasting:

//NOTE: 1 Mark = 0.4875 in 

//Position car at 330 
celerate(4, 0, 40, 2); 
//394 marks = 16ft * 12in/ft * 1 mark / 0.4875 in 
goToAbsolutePosition(394); 
//shut off motor and let coast 
motorSpeed(4, 0);

Reverse motor braking:

//NOTE: 1 Mark = 0.4875 in

//Position car at 330
 celerate(4, 0, 40, 2);
 //394 marks = 16ft * 12in/ft * 1 mark / 0.4875 in
 goToAbsolutePosition(394);
 //reverse and apply power for 1 sec
 reverse(4);
 motorSpeed(4, 100);
 goFor(0.5);
 //shut off motor and let coast
 motorSpeed(4, 0);

Prototype 2 was tested in aR+D 2. The outline for the code was the same. However, power percentage was decreased to 25%. 40% spun the wheels at a speed that Division D was uncomfortable testing. To view the design for prototype 2, see design evolution.

//NOTE: 1 Mark = 0.4875 in 

//Position car at 330 
celerate(4, 0, 25, 2); 
//394 marks = 16ft * 12in/ft * 1 mark / 0.4875 in 
goToAbsolutePosition(394); 
//shut off motor and let stop
motorSpeed(4, 0);

To view the energy vs. time graphs for these runs, see data analysis tool.

Performance Test 1

The following code was used to propel the AEV from the starting point to the gate, wait 7 seconds to activate the gate, and proceed through past the gate, stopping at an arbitrary point along the track.

//BEVIS DEVISE DIVISION D
//RUNTIME INSTRUCTIONS

//MCR States: 1 Mark = 0.4875 in
//USE DATA CHART TO DETERMINE PROPER MARKS!
void myCode()
{
 int topSpeed = 28;
 int slowSpeed = 17;
 int afterGate = 35;
 int accelerationTime = 0.5;

int slowDownDistance = 20;
 
 int distanceToGate = 283;
 int distanceToLoad = 330;


//----------------------------------------------STARTING DOCK
 //OVERCOME STARTING TORQUE
 celerate(4, 0, topSpeed, accelerationTime);
 //TRAVEL TO SLOW DOWN POSITION
 //goToAbsolutePosition(-distanceToGate + slowDownDistance);
 ///DEACCELERATE RIGHT BEFORE GATE
 //celerate(4, topSpeed, slowSpeed, accelerationTime);
 //TRAVEL TO GATE POSITION
 goToAbsolutePosition(-distanceToGate + slowDownDistance);
 //STOP AT GATE
 celerate(4, topSpeed, 0, 1.5);

/*CHECK CURRENT POSITION AND ADJUST IF NECCESARY
 * getVehiclePosition();
 * if(getVehiclePosition() < -distanceToGate){
 * //reverse
 * }
 * 
 */
 
 //WAIT 10 SECONDS
 goFor(8);
 //-------------------------------------------------------GATE
 //ACCELERATE OUT OF GATE
 celerate(4, 0, afterGate, accelerationTime);
 //TRAVEL TO LOAD POSITION
 goToAbsolutePosition(-distanceToLoad);
 //STOP AT LOAD
 motorSpeed(4, 0);

//-----------------------------------------------LOADING ZONE
 
 //-------------------------------------------------------GATE
 
 //----------------------------------------------STARTING DOCK
}

Performance Test 2

Building on performance test 2, the AEV starts out, activates the gate, and proceeds along the track to the loading zone, where the AEV brakes and magnetically attaches to the caboose. The AEV then reverses, pulling the caboose out of the loading zone, stopping at an arbitrary point. The addition of a range for the gate positions allows for variation in batteries.

//BEVIS DEVISE DIVISION D
//RUNTIME INSTRUCTIONS
//MCR States: 1 Mark = 0.4875 in

void myCode()
{
 //SPEEDS
 int accelerationSpeed = 25;
 int topSpeed = 20, loadSpeed = 25;

//TIMES
 int accelerationTime = 0.5, stoppingTime = 0.25;

//DISTACE
 //NOTE: FULL BATTERY USE 204 HALF BAT USE 209 LOW BAT USE 211
 int distanceToGate = 206;
 int distanceToLoad = 502;
 int backToGate = 454;

//----------------------------------------------STARTING DOCK
 
 //OVERCOME STARTING TORQUE
 celerate(4, 0, accelerationSpeed, accelerationTime);
 //SET TO RUN SPEED
 celerate(4, accelerationSpeed, topSpeed, accelerationTime);
 //GO TO GATE POSITION
 goToAbsolutePosition(-distanceToGate);
 //ACCELERATE TO REST
 celerate(4, topSpeed, 0, stoppingTime);
 motorSpeed(4, 0);
 //WAIT 10 SECONDS
 goFor(6.5);
 
 //-----------------------------------------------------------IN FRONT OF GATE
 
 //ACCELERATE OUT OF GATE
 celerate(4, 0, accelerationSpeed, accelerationTime);
 //SET TO RUN SPEED
 celerate(4, accelerationSpeed, topSpeed, accelerationTime);
 //TRAVEL TO LOAD POSITION
 goToAbsolutePosition(-distanceToLoad);
 //STOP AT CABOOSE
 celerate(4, topSpeed, 0, 0.5);
 
 //---------------------------------------------------------------LOADING ZONE
 
 //WAIT 5 SECONDS
 goFor(4.75);
 //REVERSE MOTOR
 reverse(4);
 //ACCELERATE OUT OF GATE
 celerate(4, 0, loadSpeed, accelerationTime);
 //TRAVEL BACK TO GATE
 //FULL BAT: HALF BAT: LOW BAT:
 //NOTE: 420 and 440 hit the gate, trying 460
 goToAbsolutePosition(-454);
 //STOP AT GATE
 celerate(4, loadSpeed, 0, stoppingTime);
 //WAIT FOR 7 SECONDS
 goFor(7);
 
 //----------------------------------------------------------------BEHIND GATE
 
 
 //--------------------------------------------------------------STARTING DOCK
 
}

Performance Test 3

Performance Test 3, the final performance test, further builds on the previous testing. After picking up the caboose at the loading dock, the AEV with its cargo proceeds back to the gate, stops for 7 seconds, activates the gate, and proceeds through back to the loading zone. The AEV and caboose stops in between the first and second track mounting posts for a successful run.

//BEVIS DEVISE DIVISION D
//RUNTIME INSTRUCTIONS
//MCR States: 1 Mark = 0.4875 in

void myCode()
{
 //SPEEDS
 int accelerationSpeed = 25;
 int topSpeed = 20, loadSpeed = 25, pastGateSpeed = 25;

//TIMES
 int accelerationTime = 0.5, stoppingTime = 0.25;

//DISTACE
 //NOTE: FULL BATTERY USE 204 HALF BAT USE 209 LOW BAT USE 211
 int distanceToGate = 206;
 int distanceToLoad = 502;
 int backToGate = 454;
 int backToStartingDock = 200;


//----------------------------------------------STARTING DOCK
 
 //OVERCOME STARTING TORQUE
 celerate(4, 0, accelerationSpeed, accelerationTime);
 //SET TO RUN SPEED
 celerate(4, accelerationSpeed, topSpeed, accelerationTime);
 //GO TO GATE POSITION
 goToAbsolutePosition(-distanceToGate);
 //ACCELERATE TO REST
 celerate(4, topSpeed, 0, stoppingTime);
 motorSpeed(4, 0);
 //WAIT 10 SECONDS
 goFor(6.5);
 
 //-----------------------------------------------------------IN FRONT OF GATE
 
 //ACCELERATE OUT OF GATE
 celerate(4, 0, accelerationSpeed, accelerationTime);
 //SET TO RUN SPEED
 celerate(4, accelerationSpeed, topSpeed, accelerationTime);
 //TRAVEL TO LOAD POSITION
 goToAbsolutePosition(-distanceToLoad);
 //STOP AT CABOOSE
 celerate(4, topSpeed, 0, 0.5);
 
 //---------------------------------------------------------------LOADING ZONE
 
 //WAIT 5 SECONDS
 goFor(4.75);
 //REVERSE MOTOR
 reverse(4);
 //ACCELERATE OUT OF GATE
 celerate(4, 0, loadSpeed, accelerationTime);
 //TRAVEL BACK TO GATE
 //FULL BAT: HALF BAT: LOW BAT:
 //NOTE: 420 and 440 hit the gate, trying 460
 goToAbsolutePosition(-backToGate);
 //STOP AT GATE
 celerate(4, loadSpeed, 0, stoppingTime);
 //WAIT FOR 7 SECONDS
 goFor(6.5);
 
 //----------------------------------------------------------------BEHIND GATE
 
 //ACCELERATE OUT OF GATE
 celerate(4, 0, accelerationSpeed, accelerationTime);
 //SET TO LOAD SPEED
 celerate(4, accelerationSpeed, loadSpeed, accelerationTime);
 //GO TO STARTING DOCK POSITION
 goToAbsolutePosition(-backToStartingDock);
 //ACCELERATE TO REST
 celerate(4, loadSpeed, 0, 0.5);
 
 //--------------------------------------------------------------STARTING DOCK
 
 motorSpeed(4, 0);
}