astro-pi / python-sense-emu

An emulator for the Raspberry Pi Sense HAT
https://sense-emu.readthedocs.io/
Other
40 stars 25 forks source link

Roll, pitch and yaw sliders in GUI have no effect #19

Closed spl237 closed 6 years ago

spl237 commented 7 years ago

My reading of the code is that the roll, pitch and yaw sliders should change values in /dev/shm/rpi-sense-emu-imu, specifically the last three pairs of bytes in the file.

Moving the sliders has no effect on these bytes; they stay at zero no matter what the sliders are set to.

The effect of this can be seen in the python code:

from sense_emu import SenseHat
sense = SenseHat()
while True:
  orient = sense.get_orientation()
  print (orient['pitch'])

If this code is run and the pitch slider is moved, the value on the console never changes from 0.0.

Running the same code with e.g. sense.get_temperature() shows the temperature value changing as expected with the slider; it only seems to be the roll, pitch and yaw sliders which have no effect.

spl237 commented 7 years ago

Further investigation suggests that the problem is in imu.py, in the function set_orientation - this reads

    def set_orientation(self, orientation, position=None):
        assert self.simulate_world
        if position is None:
            position = O
        self._orientation = V(*orientation)
        self._position = V(*position)

If I change assert self.simulate_world to assert not self.simulate_world, and add the line self._world_write(timestamp()) at the end of the function, as other similar functions have, the code behaves as expected and values update correctly.

waveform80 commented 7 years ago

Weird - with a checkout from the v1.0 tag, I can't reproduce, but I can with the released version. Not sure what's going on there (whether the version in the Raspbian repos was built from an earlier commit - the v1.0 tag is slightly after where I committed the bump in changelog). Anyway, it seems to be fixed in master and it's about time I did a release anyway to get the resizing version out there (was hoping to get time to add fuzzing to the orientation emulation, but that's not happened yet), so I'll get that done shortly.

waveform80 commented 7 years ago

Ah, slightly more complex than I thought: depends on the state of the IMU simulation. If perturbed emulation is enabled ("Simulate ... Internal measurement unit" in preferences) then it works, otherwise it fails - that's why it appears to work in some cases but not others (also because the default for the preferences is hardware dependent). Don't think the fix is too complex though - should have it sorted out shortly.

spl237 commented 6 years ago

Has anything happened on this? It's over a year since I reported it, and a year and a half since the last commit to this repo, so I'm guessing not? Could we please have a fix asap? We are in the process of preparing documentation for this application, and the fact that it doesn't work properly will become obvious!

bennuttall commented 6 years ago

I've spoken to @waveform80 about this and he's going to try to fix it shortly:

(12:42:55) waveform: ah, that's why I didn't push it. It only solves part of the problem; when simulation is disabled it allows the sliders to control orientation but the derived gyro and accelerometer readings are still zero (because the world simulation thread is the bit that calculates those, and it's not running) (12:43:53) ben_nuttall: right. what's the fix? (12:44:48) waveform: just thinking - there's a reason I didn't do the "simple" thing and just have it update the gyro and accel readings on every move of the sliders; that's because that winds up being ridiculously heavy (CPU wise) on the A+ and Zero which are exactly the platforms on which simulation is disabled by default (12:45:02) ben_nuttall: ok (12:45:30) waveform: rather the calculations need to be split out of the simulation thread into a separate method, then some logic added to update the gyro and accel readings from the sliders if and only if some timer has elapsed since the last calculation (12:46:14) waveform: it's not actually that difficult if you know your way around the code - I can probably get it done soon (12:46:45) ben_nuttall: ok great (12:47:15) waveform: and there's several new bits that really need releasing anyway (since the last release, I corrected the gamma output so the display emulation is much more realistic, and improved the rendering logic for resized windows)