Programming Basics

Codes for Scenario 1 and all future lab codes.

The programming platform used is Arduino, an open source programming software. Based on our AEV project, we apply some basic function calls into the program to get a full running code of the AEV system.

For example

  1. To accelerate or decelerate the motors we use celerate(m,p1,p2,t);
  2. To run motor(m) for a certain time(s) we use motorSpeed(m,p);
  3.  Followed by that we state the time goFor(s);
  4. To Brake the motors, we use brake(m);
  5. To reverse we use reverse(m);
  6. To go to a relative Position, we use goToRelativePosition(n);
  7. To go to an absolute position, we use goToAbsolutePosition(n)

where, M=motor, can be known as

  • M=1=Motor 1,
  • M2=2=Motor 2,
  • M=4=All Motors

p=power(%), can be distinguished,

  • p1=initial power%
  • p2=final power%

t=time(s)

n=distance,(number of marks)

 

We then keyed in Scenario 1 in to the Arduino following the proper basic function calls.

void mycode()

{

celerate(1, 0, 15, 2.5);
// Run motor one at a constant speed (15% power) for 1 s.
motorSpeed(1, 15);
goFor(1);
// Brake motor one.
brake(1);
// Accelerate motor 2 to 27% for 4s.
celerate(2, 0, 27, 4);
//Run motor 2 at 27% for 2.7s.
motorSpeed(2, 27);
goFor(2.7);
//Decelerate motor 2 from 27% to 15% in 1s.
celerate(2, 27, 15, 1);
//Brakes motor 2.
brake(2);
//reverse motor 2
reverse(2);
//Accelerate all motors to 31% for 2s.
celerate(4, 0, 31, 2);
//Run all motors at 35% for 1s.
motorSpeed(4, 35);
goFor(1);
//Brakes motor 2.
brake(2);
//Run motor 1 at 35% for 3s.
motorSpeed(1, 35);
goFor(3);
//Brakes all motors for 1s.
brake(4);
goFor(1);
//Reverse motor 1.
reverse(1);
//Accelerate motor 1 to 19% for 2s.
celerate(1, 0, 19, 2);
//Run motor 2 at 35% and run motor 1 at 19% for 2s.
motorSpeed(2, 35);
motorSpeed(1, 19);
goFor(2);
//Run all motors at 19% for 2s.
motorSpeed(4, 19);
goFor(2);

//Decelerate all motors from 19% to 0% for 3s.
celerate(4, 19, 0, 3);
//Brake all motors.
brake(4);

}

 

Another code we did was for the AEV to navigate along the straight track.

We decided to make the motors run at 40% to meet the requirement of power needed to move the AEV. The program is as shown below,

void mycode()

{

//Accelerate all motors in 5s.
celerate(4,0,40,5);
// Run all motors at a constant speed (40% power) for 2 s.
motorSpeed(4,40);
goFor(2);
//reverse all motors
reverse(4);
//run all motors at a constant speed (40%) for 2s.
motorSpeed(4,40);
goFor(2);
// Brake all motors.
brake(4);
//Save program as CSS1.

}