Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInfraredSensorSeek: 'float' object is not subscriptable #78

Open
lmoellendorf opened this issue Jan 16, 2021 · 3 comments
Open

getInfraredSensorSeek: 'float' object is not subscriptable #78

lmoellendorf opened this issue Jan 16, 2021 · 3 comments

Comments

@lmoellendorf
Copy link

lmoellendorf commented Jan 16, 2021

Steps to reproduce

  1. On an EV3 running ev3dev-stretch-ev3-generic-2020-04-10 attach the LEGO EV3 IR sensor to sensor port 4.
  2. run this program (composed in ORL):
#!/usr/bin/python

from __future__ import absolute_import
from roberta.ev3 import Hal
from ev3dev import ev3 as ev3dev
import math
import os

class BreakOutOfALoop(Exception): pass
class ContinueLoop(Exception): pass

_brickConfiguration = {
    'wheel-diameter': 5.6,
    'track-width': 18.0,
    'actors': {
    },
    'sensors': {
        '4':Hal.makeInfraredSensor(ev3dev.INPUT_4),
    },
}
hal = Hal(_brickConfiguration)

def run():
    while not hal.isKeyPressed('escape'):
        if hal.getInfraredSensorSeek('4')[0] > 0:
            hal.drawText("Hallo", 0, 0)
        else:
            hal.drawText("Goodbye", 0, 0)

def main():
    try:
        run()
    except Exception as e:
        hal.drawText('Fehler im EV3', 0, 0)
        hal.drawText(e.__class__.__name__, 0, 1)
        hal.drawText(str(e), 0, 2)
        hal.drawText('Press any key', 0, 4)
        while not hal.isKeyPressed('any'): hal.waitFor(500)
        raise

if __name__ == "__main__":
    main()

Expected result

The code should evaluate the first item in the list returned by getInfraredSensorSeek().

Actual result

getInfraredSensorSeek() seems to return a float.

This is the traceback:

robot@ev3dev:~$ ./lupo.py
Traceback (most recent call last):
  File "./lupo.py", line 41, in <module>
    main()
  File "./lupo.py", line 31, in main
    run()
  File "./lupo.py", line 24, in run
    if hal.getInfraredSensorSeek('4')[0] > 0:
TypeError: 'float' object is not subscriptable

Further information

Maybe #56 is related?

If I change the python code like this it works as expected:

24c24
<         if hal.getInfraredSensorSeek('4')[0] > 0:
---
>         if hal.getInfraredSensorSeek('4') > 0:

If the beacon is left of the sensor (when looking from behind the sensor) the values are positive (up to 25?) else negative (down to -25?).

Further Questions

How is the sensor supposed to work? Is it similar to lejos getSeekMode?

@ensonic
Copy link
Contributor

ensonic commented Jan 17, 2021

Like like a bug in the code generator (https://github.com/OpenRoberta/openroberta-lab/blob/develop/RobotEV3/src/main/java/de/fhg/iais/roberta/visitor/codegen/Ev3PythonVisitor.java) - I am not sure where the [0] is coming from. I've tried to recreate the program and I don't get the '[0]', but I can't plug the '0 into the logic comparision block (different issues). Could you attach a screenshot of your program too?

Bildschirmfoto von 2021-01-17 15-08-33

Another issue could be the version of the robertalab package on your ev3dev image. I never had the resources to update it beyond stretch and the stretch images itself are not updated :/ So you'll need to ssh in and update the package.

We're in the process of including the hal functions in the code directly to avoid this problem, but we're not done with it yet.

@lmoellendorf
Copy link
Author

lmoellendorf commented Jan 17, 2021

I am not sure where the [0] is coming from. I've tried to recreate the program and I don't get the '[0]', but I can't plug the '0 into the logic comparision block (different issues). Could you attach a screenshot of your program too?

Yes, you cannot plug the '0' into the logic block because ORL treats the return value of getInfraredSensorSeek() as a List. This is how my program looks like:

2021-01-17-172810_1918x1038_Firefox

Another issue could be the version of the robertalab package on your ev3dev image. I never had the resources to update it beyond stretch and the stretch images itself are not updated :/ So you'll need to ssh in and update the package.

Do I have to add a special repository to update it? I already tried updating:

robot@ev3dev:~$ sudo apt update
[sudo] password for robot:
Get:1 http://security.debian.org stretch/updates InRelease [53.0 kB]
Ign:2 http://httpredir.debian.org/debian stretch InRelease
Hit:3 http://httpredir.debian.org/debian stretch Release
Hit:4 http://archive.ev3dev.org/debian stretch InRelease
Get:6 http://security.debian.org stretch/updates/main armel Packages [614 kB]
Fetched 667 kB in 39s (16.9 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
86 packages can be upgraded. Run 'apt list --upgradable' to see them.
robot@ev3dev:~$ sudo apt install openrobertalab
Reading package lists... Done
Building dependency tree
Reading state information... Done
openrobertalab is already the newest version (1.7.4+1.0.0).
0 upgraded, 0 newly installed, 0 to remove and 86 not upgraded.

@chasekhandelwal
Copy link

can anybody tell me how i am Beginner in Open source Can you tell me How I can also Contribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants