\n"); } else { header("Content-type: text/html; charset=utf-8"); } ?> CSCI 903 Assignment 10

CSCI-903 Assignment 10

Assignment

Program your Teagueduino to control two servo motors, connected to two wheels or pulleys, so that three switches will control the robot’s movements. You can make up your own input codes, but these are the ones we used in class:

In_1 In_2 In_3 function Out_A (Left Wheel) Out_B (Right Wheel)
0 0 0 Stop Neutral Neutral
0 0 1 Turn Right CCW Neutral
0 1 0 Forward CCW CW
0 1 1
1 0 0 Turn Left Neutral CW
1 0 1 Backwards CW CCW
1 1 0
1 1 1

The output values are listed as “CW” for “clockwise,” “CCW” for “counterclockwise,” and “Neutral” for “no motion.” The table gives the motor directions as you face the motors from the outside, looking in. You may need to experiment to determine whether CW is produced by an output value of 0 and CCW by an output value of 1000, or vice-versa. Also, the output value that makes a motor stop moving, (“Neutral” in the table) varies from one servo motor to another. In class we handled this situation by using two variables to hold the neutral values for the two motors, which should be determined by experiment, and then assigned to the two variables during the setup phase of the code.

A simple solution to coding the controller would be to code five triply-nested if statements, one for each function, requiring 8 lines of code for each function, a total of 40 lines. But the code can be written more efficiently by observing that the same tests are repeated unnecessarily using this approach. For example, once the code determines that both In_1 and In_2 are false, it can set Out_B to Neutral, and then use if-else to decide whether Out_A needs to be set to Neutral or CCW.

An optional coding challenge is to incorporate two additional functions, “Pivot Right” and “Pivot Left.” For example, if both motors go CW, the robot will pivot to the left as the right side goes forward and the left side goes backwards. From a human factors perspective, input codes of 011 for pivot right and 110 for pivot left seem to make sense.

Then, if you have seven of the eight input possibilities accounted for, it would make sense to do something “intelligent” for the eighth input combination. What should it be?