This video showed the turning and moving in action and below I'll explain the code.
This code is to test the turning function.
Line 1 clears the workspace.
Line 2 defines "a" as the connected arduino.
Lines 3 and 4 define "sRight" and "sLeft" as the two servos connected to pins 11 and 12.
Line 5 runs the turn function passing it the two servos and the speed and angle.
Line 1 defines the function called turn which takes 2 servos as inputs and the speed, between 0 and 1, and the angle you want it to turn to in degrees.
Lines 2 and 3 defines "leftSpeed" and "rightSpeed" as the speeds which the two servos need to go at to move forwards in accordance with the speed.
Line 4 defines "zeroSpeed" as the speed which both of the servos need to go at to be still.
Line 5 start a parallel for loop which will loop twice.
Lines 6-10 a set of if statements which say that on one run of the loop one servo will start on the next loop the other will start and as its a parfor in theory they should both happen at the same time.
Line 11 ending the parfor.
Line 12 waits for the right amount of time to make it turn to the inputted angle.
Lines 13 and 14 turn off the servos.
Line 15 end the function.
This code is to test the moving function.
Line 1 clears the workspace.
Line 2 defines "a" as the connected arduino.
Lines 3 and 4 define "sRight" and "sLeft" as the two servos connected to pins 11 and 12.
Line 5 runs the move function passing it the two servos and the speed and angle.
Line 1 defines the function called move which takes 2 servos as inputs and the speed, between 0 and 1, and the distance you want it to go to in cm.
Lines 2 and 3 defines "leftSpeed" and "rightSpeed" as the speeds which the two servos need to go at to move forwards in accordance with the speed.
Line 4 defines "zeroSpeed" as the speed which both of the servos need to go at to be still.
Line 5 start a parallel for loop which will loop twice.
Lines 6-10 a set of if statements which say that on one run of the loop one servo will start on the next loop the other will start and as its a parfor in theory they should both happen at the same time.
Line 11 ending the parfor.
Line 12 waits for the right amount of time to make it move to the inputted distance.
Lines 13 and 14 turn off the servos.
Line 15 end the function.
Apologies for the monotony of that.
One final post coming soon...
Alexander



