imurvai / brickcontroller2

Cross platform application for controlling Lego creations using a bluetooth gamepad.
108 stars 32 forks source link

Fix SBrick quirk: keep the direction the same when setting an output to zero #52

Closed pdw-mb closed 3 years ago

pdw-mb commented 3 years ago

Fixes #51.

I did a bit of refactoring as using separate variables for the channels was getting a bit unwieldy by the time we have to remember the last output direction.

imurvai commented 3 years ago

Hi, I don't really get why this change is for. Could you explain a little bit in detail?

pdw-mb commented 3 years ago

Have a look at this video and watch the turn signal on the right. Notice the slight flash on the right when the signal on the left turns off. The video only caught it twice, but it actually happens every time.

The signal on the right is activated by +1 on the SBrick output, and the one on the left is activated by -1. This is running a sequence that alternates between -1 and 0. The transition from -1 to 0 causes a brief +ve blip.

BC2 always sets direction = forwards when setting an output to off. Obviously the direction shouldn't make a difference when you're turning an output off, but it does. This patch sets the direction to the last used direction when turning an output off.

I suspect that using "brake" mode on the SBrick would also fix it, but that would change how motors behave.