ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
425 stars 144 forks source link

Fix gyro sensor reset #692

Closed dlech closed 4 years ago

dlech commented 4 years ago

Gyro sensor reset was failing because we were writing 17 bytes of 0 to the gyro sensor instead of the byte 17.

Also change it to a bytes literal for max efficiency.

dlech commented 4 years ago

I'm guessing from the trailing comma, what I originally meant to do was bytes((17,)) which would have been correct. Apparently a trailing comma doesn't work inside of arguments like x = 17, does.

ghost commented 4 years ago

What release will this change be in?

dlech commented 4 years ago

As a workaround, you can create a subclass of GyroSensor with the fix and use it instead.

class GyroSensor2(GyroSensor):
    def reset(self):
        self._direct = self.set_attr_raw(self._direct, 'direct', b'\x11')
WasabiFan commented 4 years ago

Fix released in v2.0.0. See our FAQ for upgrade commands. Let me know if there are any issues.

ghost commented 4 years ago

Thanks for the solution.

Right now the kids read the gyro at the start of their mission runs when the robot faces North on the FLL table.

They pass that to all the move functions they've written as an argument called Gyro_Offset.

Then they have a function called Gyro_Angle that reads the gyro and subtracts the offset to get a "table relative" angle, every time they need an angle.

If we have time before our competition, we'll implement your suggestion.

Cheers!

On Sun, Nov 24, 2019, 11:58 PM David Lechner notifications@github.com wrote:

As a workaround, you can create a subclass of GyroSensor with the fix and use it instead.

class GyroSensor2(GyroSensor): def reset(self): self._direct = self.set_attr_raw(self._direct, 'direct', b'\x11')

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ev3dev/ev3dev-lang-python/pull/692?email_source=notifications&email_token=AFBYYSVHNFCPMGVGOU5EFALQVNLPVA5CNFSM4JQ4SOCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFBD2JQ#issuecomment-557989158, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBYYSSPGKVQBZQVJVLHGUTQVNLPVANCNFSM4JQ4SOCA .