Arduino Code Division H

Arduino Code Guide

A basic coding guide with the commands used throughout the AEV project [1].

celerate(m,p1,p2,t): Accelerates or decelerates the motor (m) from start power (p1) % to end power (p2) % over the time (t) seconds.

motorSpeed(m,p): Initializes motor (m) at power (p) %

goFor(t): Runs the motor (m) at initialized state for (t) seconds

brake(m): Brakes motor (m)

reverse(m): Reverses the polarity of motor (m)

goToRelativePosition(n): Runs the motors at initialized state until it reaches (n) marks

goToAbsolutePosition(n): Runs the motors at initialized state until it reaches the (n) mark from the starting position

Scenario 1 Code

celerate(1,0,15,2.5); //Accelerate motor one from start 15% power in 2.5 seconds
goFor(1); //Run motor one at a constant speed for 1 second
brake(1); //Brake motor 1
celerate(2,0,27,4); //Accelerate motor two from start to 27% power in 2.7 seconds
goFor(2.7); //Run motor two at a constant speed for 2.7 seconds
celerate(2,27,15,1); //Decelerates motor two from 27% to 15% power in 1 seconds
brake(2); //Brake motor 2
reverse(2); //Reverses motor 2
celerate(4,0,31,2); //Accelerate all motors from 31% to 2%
goFor(1); //Runs both motors at a constant speed for 1 second
brake(2); //Brake motor 2
goFor(3); //Runs motor for 3 seconds
brake(4); //Brakes all motors
goFor(1); //All motors don’t move in 1 second
reverse(1); //Reverse motor 1
celerate(1,0,19,2); //Accelerates motor 1 from 0 to 19% in 2 seconds
motorSpeed(2,35); //Sets motor 2 to 36% power
goFor(2); //All motors run at the constant speed for 2 seconds
motorSpeed(4,19); //All motors are set to 19%
goFor(2); //All motors run at the constant speed for 2 seconds
celerate(4,19,0,3); //Decerlates all motors from 19% power to 0% power in 3 seconds
brake(4); //Stops all motors

Scenario 2 Code

motorSpeed(4,25); //set all motors to 25% power
goFor(2); //run motors at a constant speed for 2 seconds
motorSpeed(4,20); //set all motors to 20% power
goToAbsolutePosition(295); //run motors until they travel a total distance of 12 feet (295 marks)
reverse(4); //reverse all motors
motorSpeed(4,30); //sets all motors to a speed of 30% power
goFor(1.5); //runs motors at a constant speed for 1.5 seconds
brake(4); //brakes all motors