You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IR sensor doesn't respond to toggling off the "beacon" button #498
What's the behavior you are seeing (physically with the motors)? It seems to me from the log that it does what you expect -- the hand motor starts when you press the button on the remote and stops when the touch sensor is pressed. Which part of that isn't working?
The hand motor doesn't always start when beacon is pressed. As described in the second anomaly, if started and stopped, it will not start again until I execute the first anomaly (which is that I have to run a large motor with any other button and enters without permission nor call the move(state) in auto_home which is only assigned to beacon
OK, I see what you're saying (I think); the beacon stops firing events after the first or second usage. I'll take a look later today and see if I can repro.
I just pulled out my IR sensor and remote to try this out, When I press one of the up/down buttons, the light that indicates it's sending a signal lights up for a bit then turns off. But when I press the button in the top-center (which I believe is the one you are referring to here), it turns on and doesn't turn off. So, it seems that the built-in behavior of the remote is that the top-center button is a toggle rather than a "hold". That button de-activates when another button is pressed or when you press it again.
@WasabiFan indeed. as dwalton said it is the intended behaviour of the beacon button. problem is that toggling it off and back on again does not run the medium_motor again unless you click the other up/down buttons
Ok, I had assumed you were just mis-understanding the behavior of the beacon 😆
This turned out to be a bit of a Schrödinger's cat situation, but after a bit of head-scratching at 20-past-midnight I've localized the problem: a peculiar interaction between setting the mode of the sensor rapidly and the driver responding to updates.
I notice something (which isn't inherently wrong, but might help in debugging the observations that follow): When I toggle the beacon button off, it takes a second or two for the console output to reflect that. Other buttons are generally immediate.
Now, after toggling the button a few times and observing that it is responsive, I run this in a separate window simultaneously:
With this running, the button data no longer behaves the same. "9" (for the beacon button) never resets to 0 after toggling the button off. The other buttons still work. To put it differently, setting the sensor mode frequently makes that particular button report turning on but never off. In the case of our Python library, setting the mode is always done immediately before reading the sensor value to ensure the correct behavior.
Another observation: It appears that setting the mode is faster when the beacon is toggled on. Not sure how that's involved here.
@dlech Do you have any idea what might be going on here? I know it's a UART sensor, so AFAIK setting the mode translates directly to a serial write... is this a behavior of the sensor itself rather than the ev3dev driver? I find it hard to imagine why our driver would treat that button differently otherwise.
setting the mode translates directly to a serial write... is this a behavior of the sensor itself rather than the ev3dev driver
This is intentional on the part of the driver. Some (very few) modes (e.g. the oneshot ultrasonic sensor mode US-SI-CM) won't update the value return unless the mode is set.
Do you have any idea what might be going on here?
Are there any error messages in dmesg? I seem to vaguely recall someone else reporting temperamental behavior of the LEGO EV3 IR sensor, but I have no idea where that might be.
This is intentional on the part of the driver. Some (very few) modes (e.g. the oneshot ultrasonic sensor mode US-SI-CM) won't update the value return unless the mode is set.
I am not sure if you answered the question better than I expected or if I didn't ask what I thought I was asking; it should have instead been:
I know it's a UART sensor, so AFAIK setting the mode translates directly to a serial write... is the lack of a change after releasing the button a behavior of the sensor itself rather than the ev3dev driver?
Are there any error messages in dmesg? I seem to vaguely recall someone else reporting temperamental behavior of the LEGO EV3 IR sensor, but I have no idea where that might be.
There were some buffer overrun errors earlier in the log (I don't think they were related) but none after plugging in the IR sensor. I can do a more thorough check with a reboot later today.
I think the delay after toggling the beacon button off is a feature of the sensor. If the value gets stuck on and won't toggle back off, then that sounds like a hardware bug.
OK... so it sounds like we need to work around this by not setting the mode every time. Perhaps this is a good time to revisit the policy of always setting the mode before reading (which results in what I believe is a significant perf hit).
changed the title [-]rc_tank.py: inheriting/expanding class behaves incorrectly[/-][+]IR sensor doesn't respond to toggling off the "beacon" button[/+]on Aug 31, 2018
While I'm ruminating on a proper fix, here's a workaround for anyone hitting the same issue:
importtime# Don't import InfraredSensor herefromev3dev2.sensorimportSensorimportev3dev2.sensor.lego# Workaround for https://github.com/ev3dev/ev3dev-lang-python/issues/498classInfraredSensor(ev3dev2.sensor.lego.InfraredSensor):
def__init__(self, address=None, name_pattern=Sensor.SYSTEM_DEVICE_NAME_CONVENTION, name_exact=False, **kwargs):
super(InfraredSensor, self).__init__(address, name_pattern, name_exact, **kwargs)
@ev3dev2.sensor.lego.InfraredSensor.mode.setterdefmode(self, value):
ifself.mode!=value:
super(InfraredSensor, self.__class__).mode.fset(self, value)
# Demo of working sensorir=InfraredSensor()
defbeacon_action(state):
print("beacon: %s"%state)
ir.on_channel1_beacon=beacon_actionprint("Watching on channel 1 for beacon button...")
whileTrue:
ir.process()
time.sleep(0.01)
Modify the imports in your script to remove the InfraredSensor import and add the two above, then paste in that new class. It should be a drop-in replacement.
Activity
Uldiniad commentedon Aug 17, 2018
@WasabiFan opened as requested
WasabiFan commentedon Aug 17, 2018
What's the behavior you are seeing (physically with the motors)? It seems to me from the log that it does what you expect -- the hand motor starts when you press the button on the remote and stops when the touch sensor is pressed. Which part of that isn't working?
Uldiniad commentedon Aug 17, 2018
The hand motor doesn't always start when beacon is pressed. As described in the second anomaly, if started and stopped, it will not start again until I execute the first anomaly (which is that I have to run a large motor with any other button and enters without permission nor call the
move(state)in auto_home which is only assigned to beaconWasabiFan commentedon Aug 17, 2018
OK, I see what you're saying (I think); the beacon stops firing events after the first or second usage. I'll take a look later today and see if I can repro.
Uldiniad commentedon Aug 17, 2018
yes, that's correct, and instead the other buttons on the same channel fire that event which then allows beacon to fire its event again... 🤷♂️
WasabiFan commentedon Aug 19, 2018
I just pulled out my IR sensor and remote to try this out, When I press one of the up/down buttons, the light that indicates it's sending a signal lights up for a bit then turns off. But when I press the button in the top-center (which I believe is the one you are referring to here), it turns on and doesn't turn off. So, it seems that the built-in behavior of the remote is that the top-center button is a toggle rather than a "hold". That button de-activates when another button is pressed or when you press it again.
dwalton76 commentedon Aug 19, 2018
yep that button toggles the IR beacon on/off
Uldiniad commentedon Aug 20, 2018
@WasabiFan indeed. as dwalton said it is the intended behaviour of the beacon button. problem is that toggling it off and back on again does not run the medium_motor again unless you click the other up/down buttons
WasabiFan commentedon Aug 20, 2018
Ok, I had assumed you were just mis-understanding the behavior of the beacon 😆
This turned out to be a bit of a Schrödinger's cat situation, but after a bit of head-scratching at 20-past-midnight I've localized the problem: a peculiar interaction between setting the mode of the sensor rapidly and the driver responding to updates.
@dlech:
If I have an IR sensor plugged in and do the following (with appropriate path, of course):
I notice something (which isn't inherently wrong, but might help in debugging the observations that follow): When I toggle the beacon button off, it takes a second or two for the console output to reflect that. Other buttons are generally immediate.
Now, after toggling the button a few times and observing that it is responsive, I run this in a separate window simultaneously:
With this running, the button data no longer behaves the same. "9" (for the beacon button) never resets to 0 after toggling the button off. The other buttons still work. To put it differently, setting the sensor mode frequently makes that particular button report turning on but never off. In the case of our Python library, setting the mode is always done immediately before reading the sensor value to ensure the correct behavior.
Another observation: It appears that setting the mode is faster when the beacon is toggled on. Not sure how that's involved here.
@dlech Do you have any idea what might be going on here? I know it's a UART sensor, so AFAIK setting the mode translates directly to a serial write... is this a behavior of the sensor itself rather than the ev3dev driver? I find it hard to imagine why our driver would treat that button differently otherwise.
dlech commentedon Aug 20, 2018
Looks like I observed the same thing way back when: http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensor_data.html#lego-ev3-ir-mode3-value0
This is intentional on the part of the driver. Some (very few) modes (e.g. the oneshot ultrasonic sensor mode
US-SI-CM) won't update the value return unless the mode is set.Are there any error messages in
dmesg? I seem to vaguely recall someone else reporting temperamental behavior of the LEGO EV3 IR sensor, but I have no idea where that might be.WasabiFan commentedon Aug 20, 2018
I am not sure if you answered the question better than I expected or if I didn't ask what I thought I was asking; it should have instead been:
There were some buffer overrun errors earlier in the log (I don't think they were related) but none after plugging in the IR sensor. I can do a more thorough check with a reboot later today.
dlech commentedon Aug 20, 2018
I think the delay after toggling the beacon button off is a feature of the sensor. If the value gets stuck on and won't toggle back off, then that sounds like a hardware bug.
WasabiFan commentedon Aug 20, 2018
OK... so it sounds like we need to work around this by not setting the mode every time. Perhaps this is a good time to revisit the policy of always setting the mode before reading (which results in what I believe is a significant perf hit).
[-]rc_tank.py: inheriting/expanding class behaves incorrectly[/-][+]IR sensor doesn't respond to toggling off the "beacon" button[/+]WasabiFan commentedon Sep 3, 2018
While I'm ruminating on a proper fix, here's a workaround for anyone hitting the same issue:
Modify the imports in your script to remove the
InfraredSensorimport and add the two above, then paste in that new class. It should be a drop-in replacement.Uldiniad commentedon Sep 13, 2018
thanks @WasabiFan much appreciated
WasabiFan commentedon Sep 13, 2018
Yeah, thanks for doing the initial investigation. FWIW until we release the package with this change the workaround above is still the best way to go.
WasabiFan commentedon Sep 24, 2018
Fix released in
2.0.0~beta2. To upgrade:The workaround posted above can be removed from user code.