Description

Fundamentally, the software for reading the throttle command is nothing more than reading the AD pin to which the potentiometer is connected. However, since the communications protocol describes a set of 15 discrete velocity commands, rather than a continuous duty cycle from -100 to 100, the software becomes a little more complicated. After reading the AD pin, it is determined how far the input value is from the center-point of the throttle (which is not necessarily the same as the midpoint of the AD system), in terms of how many discrete divisions from the center-point have to be passed in order to reach that input value. Both the throttle center-point and the size of each division were determined empirically, so that the throttle would be vertical for zero velocity command, and that the maximum velocity command was achieved for a reasonable amount of throttle lever travel. Once the input is discretized, it is converted to a four-bit code as dictated by the communications protocol. Since the forward velocity portion of the velocity command is to be transmitted as the upper nibble of the parameter byte, these four bits are shifted left four times and returned as an 8-bit number. Since the lower four-bits are now all zeros, concatenation with the rotational velocity command will be possible with a simple addition operation.

Pseudo-Code

GetTranslationalVelocity:
    Read the value of the analog input pin AD0
    If the value is within one negative division of the throttle center
        Construct four bits representing “-0” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within two negative divisions of the throttle center
        Construct four bits representing “-15” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within three negative divisions of the throttle center
        Construct four bits representing “-29” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within four negative divisions of the throttle center
        Construct four bits representing “-45” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within five negative divisions of the throttle center
        Construct four bits representing “-59” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within six negative divisions of the throttle center
        Construct four bits representing “-75” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within seven negative divisions of the throttle center
        Construct four bits representing “-89” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is beyond seven negative divisions of the throttle center
        Construct four bits representing “-100” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within one positive division of the throttle center
        Construct four bits representing “0” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within two positive divisions of the throttle center
        Construct four bits representing “15” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within three positive divisions of the throttle center
        Construct four bits representing “29” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within four positive divisions of the throttle center
        Construct four bits representing “45” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within five positive divisions of the throttle center
        Construct four bits representing “59” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within six positive divisions of the throttle center
        Construct four bits representing “75” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is within seven positive divisions of the throttle center
        Construct four bits representing “89” in the communications protocol code
        Shift these four bits left by four places
        Return the result
    Else if the value is beyond seven positive divisions of the throttle center
        Construct four bits representing “100” in the communications protocol code
        Shift these four bits left by four places
        Return the result