Arduino Code

Lab 2 : Arduino Programming Basics

Scenario 1

celerate(1,0,15,2.5);//accelerate motor 1 from 0 power to 15% power in 2.5s

goFor(1);//run AEV for 1s

brake(1);//stop motor 1

celerate(2,0,27,4);//accelerate motor 2 from 0 power to 27% power in 4s

goFor(2.7);//run AEV for 2.7s

celerate(2,27,15,1);//deccelerate motor 2 from 27% power to 15% power in 1s

brake(2);//stop motor 2

reverse(2);//reverse motor 2

celerate(4,0,31,2);//accelerate all motor from 0 power to 31% power in 2s

motorSpeed(4,35);//set all motors speed to 35% power

goFor(1);//run AEV for 1s

brake(2);//stop motor 2

goFor(3);//run AEV for 3s

brake(4);//stop all motors

goFor(1);//wait for 1s

reverse(1);//reverse spinning axis of motor 1

celerate(1, 0 , 19, 2);//accelerate motor 1 from 0 power to 19% power in 2s

motorSpeed(2,35);//set motor 2 speed to 35%

goFor(2);//run AEV for 2s

motorSpeed(4,19);//set all motors speed 19%

goFor(2);//run AEV for 2s

celerate(4, 19, 0, 3);//deccelerate all motors from 19% power to 0 power in 3s

brake(4);//stop all motors


 

Lab 3 : Concept Screening and Scoring

Scenario

reverse(4); //Reverse all motors instantly(running in the wrong direction)

celerate(4, 0, 25, 3); //Accelerate all motors from 0% to 25% in 3 seconds

motorSpeed(4, 25); //Run all motors at a constant speed(25% power)

goFor(1); //Go for 1 second

motorSpeed(4, 20); //Run all motors at 20% power

goFor(2); //Go for 2 seconds

reverse(4); //Reverse all motors

motorSpeed(4, 25); //Run all motors at a constant speed(25% power)

goFor(2); //Go for 2 seconds

brake(4); //Brake all motors

 

Lab 4 : External Sensors

Scenario

motorSpeed(4, 25);    //initialize motor speed to 25% power

goFor(2);    //run AEV for 2s

goToAbsolutePosition(394);    //run AEV for 16 feet distance

reverse(4);    //reverse all motors

motorSpeed(4, 30);    //change motor speed to 30% power

goFor(1.5);    //run AEV for 1.5s

brake(4);    //cut off power of all motors

 

Lab 6 : System Analysis 2

reverse(4); //reverse spining axis of motors

motorSpeed(4,25); //initial speed of all motors to 25% power

goFor(2); //run AEV for 2s at power of 25%

motorSpeed(4,20); //decrease motor power input down to 20%

goToAbsolutePosition(394); //run AEV for 16 feet distance

reverse(4); //reverse the spining axis of motors to slow down the AEV

motorSpeed(4,30); //speed up the AEV to 30% power

goFor(1); //run motors for 1s

brake(4);    //cut off power of all motors

 

Lab 7: Design Analysis Tool

reverse(4); //reverse spining axis of motors

motorSpeed(4,20); //increase motor power input up to 20%

goToAbsolutePosition(380); //run AEV for 380 marks

reverse(4); //reverse the spining axis of motors to slow down the AEV

motorSpeed(4,30); //speed up the AEV to 30% power

goFor(1); //run motors for 1s

brake(4);    //cut off power of all motors

reverse(4); //reverse spining axis of motors

motorSpeed(4,20); //increase motor power input up to 20%

goToRelativePosition(300); //run AEV for 300 marks

brake(4); //stop all motors

 

Lab 8: Performance Test 1 & Preliminary Design Review

Prototype Design 1

reverse(4);               //reverse spining axis of motors

celerate(4,0,25,5);    //accelerate all propellers from 0 to 25% power in 5 s

goToAbsolutePosition(378);   //run AEV for 378 marks

reverse(4);               //reverse spining axis of motors

motorSpeed(4,30);         //speed up the AEV to 30% power

goFor(1);                 //run motors for 1s

brake(4);                 //cut off power of all motors

reverse(4);               //reverse spining axis of motors

goFor(5);                 //run motors for 5s

celerate(4,0,25,5);       //accelerate all propellers from 0 to 25% in 5 s

goToRelativePosition(380);        //run AEV for 380 marks

reverse(4);               //reverse spining axis of motors

motorSpeed(4,30);         //speed up the AEV to 30% power

goFor(1);                  //run motors for 1s

brake(4);                 //cut off power of all motors

Prototype Design 2

celerate(4,0,25,5);       //accelerate all propellers from 0 to 25% power in 5 s

goToAbsolutePosition(375);  //run AEV for 375 marks

reverse(4);               //reverse spining axis of motors

motorSpeed(4,30);         //speed up the AEV to 30% power

goFor(1.5);                //run motors for 1.5s

brake(4);                 //cut off power of all motors

reverse(4);               //reverse spining axis of motors

goFor(5);                 //run motors for 5s

celerate(4,0,25,5);       //accelerate all propellers from 0 to 25% power in 5 s

goToRelativePosition(398);   //run AEV for 398 marks

reverse(4);               //reverse spining axis of motors

motorSpeed(4,30);         //speed up the AEV to 30% power

goFor(1.5);               //run motors for 1.5s

brake(4);      //cut off power of all motors

 

Lab 9: Performance Test 2

 

rotateServo(60);                               // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propelllers to 25%.

goToAbsolutePosition(441);           // Run the AEV to 441 marks away from starting position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(7);                                         // Maintain the AEV’s state for 7 seconds.

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propellers to 25%.

goToRelativePosition(440);            // Run the AEV to 441 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

 

Lab 10: Performance Test 3 

 

rotateServo(60);                               // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propelllers to 25%.

goToAbsolutePosition(440);           // Run the AEV to 440 marks away from starting position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(8);                                         // Maintain the AEV’s state for 8 seconds.

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propellers to 25%.

goToRelativePosition(450);            // Run the AEV to 450 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(5);                                          // Maintain the AEV’s state for 5 seconds.

reverse(4);                                        //Reverse the direction of the propellers

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,50*powerAdjust()); // Set the speed of propellers to 50%.

goToRelativePosition(-100);            // Run the AEV to 100 marks away from its position.

motorSpeed(4,35*powerAdjust()); // Set the speed of propellers to 35%.

goToRelativePosition(-330);            // Run the AEV to 330 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(8);                                          // Maintain the AEV’s state for 8 seconds.

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,50*powerAdjust()); // Set the speed of propellers to 50%.

goToRelativePosition(-100);            // Run the AEV to 100 marks away from its position.

motorSpeed(4,35*powerAdjust()); // Set the speed of propellers to 35%.

goToRelativePosition(-375);            // Run the AEV to 375 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

 

Lab 11: Final Test

 

rotateServo(60);                               // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propelllers to 25%.

goToAbsolutePosition(440);           // Run the AEV to 440 marks away from starting position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(8);                                         // Maintain the AEV’s state for 8 seconds.

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,25*powerAdjust()); // Set the speed of propellers to 25%.

goToRelativePosition(450);            // Run the AEV to 450 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(5);                                          // Maintain the AEV’s state for 5 seconds.

reverse(4);                                        //Reverse the direction of the propellers

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,50*powerAdjust()); // Set the speed of propellers to 50%.

goToRelativePosition(-100);            // Run the AEV to 100 marks away from its position.

motorSpeed(4,35*powerAdjust()); // Set the speed of propellers to 35%.

goToRelativePosition(-330);            // Run the AEV to 330 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

goFor(8);                                          // Maintain the AEV’s state for 8 seconds.

rotateServo(60);                              // Rotate the servo arm to 60 degree.

motorSpeed(4,50*powerAdjust()); // Set the speed of propellers to 50%.

goToRelativePosition(-100);            // Run the AEV to 100 marks away from its position.

motorSpeed(4,35*powerAdjust()); // Set the speed of propellers to 35%.

goToRelativePosition(-375);            // Run the AEV to 375 marks away from its position.

brake(4);                                          // Stop all the propellers.

rotateServo(110);                            // Rotate the servo arm to 110 degree.

 

Lab 12: Oral Presentation

No code here.