Helm
The helm has two analog inputs (one from the left stick and one from the right) and two digital inputs from the reverse buttons on the sticks. If you use the digital input as a sign bit you get a signed 9 bit number for left and right (ie -255 to 255). We need to convert that into a nibble that represents speed (0 being full back and 16 being full forward) and a direction that is 0 meaning full right and 16 meaning full left. The first thing is to add 255 to each to make a 9 bit unsigned number.
To construct the speed nibble use:
Speed = (Left + Right)/(32)
Boat
I think that divide by 32 should concat to just the 4 most significant bits.
Direction = (Right - Left)/(32)
With this encoding pounding on both drums gets full forward, zero turn. Doing nothing is zero drive zero turn. One full forward one full back gives zero speed and full turn. However you should note that with our helm it is impossible to give a full forward and full turn command. I don't believe that this is a fault of the encoding, because I cannot imagine a drumming pattern that I would expect to give that output. To turn you have to slow down. I think this is fine.
Boat
if we interpret the number coming in as -8 to 8, we need to extract a -8 to 8 value for each boat motor.
Left motor = (speed - direction)|limited to +- 8
Right motor = (speed - direction)|limited to +- 8
Incidentally I don't think that our helm will ever require the limit to +-8. I think that it is inherent in the limit in the helm and boat because we are doing tank drive. In the same way what does a drive-rudder boat do with a zero speed full turn? I'd have to think harder to be sure but I think what I said is true. Anyway: whaddyathink?Right motor = (speed - direction)|limited to +- 8
No comments:
Post a Comment