Overview | Main | State Machine | Events | IR | Tape | Drivetrain | PWM | Flash | Two Minute Timer | Bump

drivetrain.c
drivetrain.h

void drivetrainInit(void): initialize the drivetrain subsystem

void commandMotion(char cmd): send a new movement command to the drive wheels

void main(void): test harness for the drivetrain module

The drivetrain module provides a public function to accept and execute movement commands from other modules. The available commands are rotate counter-clockwise, rotate clockwise, drive forward, drive in reverse, and stop. Each movement command has two available speeds, fast and slow. The module uses two PWM pins for PWM and two output pins for direction control.

PSEUDOCODE

(Download Pseudocode .doc 27kb)

void drivetrainInit(void)
    Initialize the PWM module
    Initialize the PWM channels used by the motors
    Set the data direction of the pins used for direction control to be outputs
    Make sure the robot starts stopped

void commandMotion(char cmd)
    Stop is both wheels at 0% duty cycle
    CCW fast is left backward fast and right forward fast
    CCW slow is left backward slow and right forward slow
    CW fast is left forward fast and right backward fast
    CW slow is left forward slow and right backward slow
    Forward fast is both wheels forward fast
    Forward slow is both wheels forward slow
    Backward fast is both wheels backward fast
    Backward slow is both wheels backward slow

void main(void) **Test Harness**
    Initialize the terminal I/O subsystem
    Initialize the drivetrain module
    Repeat forever
        Get a character from the keyboard
        If the character is ‘w’
            Drive forward fast
        Else if the character is ‘a’
            Rotate counter-clockwise fast
        Else if the character is ‘s’
            Drive reverse fast
        Else if the character is ‘d’
            Rotate clockwise fast
        Else if the character is ‘x’
            Stop
        Else if the character is ‘i’
            Drive forward slow
        Else if the character is ‘j’
            Rotate counter-clockwise slow
        Else if the character is ‘k’
            Drive reverse slow
        Else if the character is ‘l’
            Rotate clockwise slow
        Else if the character is ‘m’
            Stop
        Else
            Complain about an invalid character
            Stop