OpenRoberta / robertalab-ev3dev

roberta lab connector for ev3dev
Apache License 2.0
17 stars 14 forks source link

KeyError when trying to control medium motor #29

Closed osma closed 7 years ago

osma commented 7 years ago

Hi, I just got started with ev3dev and Open Roberta, so forgive me if I've missed something obvious or am reporting in the wrong place. I have the EV3 basic track3r robot, which in addition to the tracks has a medium motor on port A for controlling various tools. So one of the first things I tried was controlling that motor.

So I logged in to OpenRoberta and set up my robot so it has a medium motor on Port A on the Robot Settings page. I also switched to the expert mode in Open Roberta to be able to access the blocks that control motors directly.

Then I created a very basic Nepo program which simply has one block that turns the motor on port A for 1 turn on speed 30.

Trying to run that program on my EV3 gives this error both on the EV3 screen and in the systemd journal:

Jan 04 07:45:18 ev3dev openrobertalab[392]: ERROR:roberta.lab:Ooops:
Jan 04 07:45:18 ev3dev openrobertalab[392]: Traceback (most recent call last):
Jan 04 07:45:18 ev3dev openrobertalab[392]: File "/usr/lib/python3/dist-packages/roberta/lab.py", line 272, in _exec_code
Jan 04 07:45:18 ev3dev openrobertalab[392]: exec(compiled_code, scope)
Jan 04 07:45:18 ev3dev openrobertalab[392]: File "/home/robot/NEPOprog.py", line 33, in <module>
Jan 04 07:45:18 ev3dev openrobertalab[392]: main()
Jan 04 07:45:19 ev3dev openrobertalab[392]: File "/home/robot/NEPOprog.py", line 23, in main
Jan 04 07:45:19 ev3dev openrobertalab[392]: run()
Jan 04 07:45:19 ev3dev openrobertalab[392]: File "/home/robot/NEPOprog.py", line 19, in run
Jan 04 07:45:19 ev3dev openrobertalab[392]: hal.rotateRegulatedMotor('A', 30, 'rotations', 1)
Jan 04 07:45:19 ev3dev openrobertalab[392]: File "/usr/lib/python3/dist-packages/roberta/ev3.py", line 268, in rotateRegulatedMotor
Jan 04 07:45:19 ev3dev openrobertalab[392]: m = self.cfg['actors'][port]
Jan 04 07:45:19 ev3dev openrobertalab[392]: KeyError: 'A'
Jan 04 07:45:19 ev3dev openrobertalab[392]: INFO:roberta.lab:status changed: registered

The EV3 display says "Press any key" in addition to the KeyError.

I'm using the most recent ev3dev build (ev3dev-jessie-ev3-generic-2016-12-21) and the openrobertalab package is version 1.6.0+1.0.0.

ensonic commented 7 years ago

Do you have the medium motor connected to port 'A'? Could you also attach the program or a screenshot with the code? You can export the program from the menu, or do "Show code" and take a screenshot.

osma commented 7 years ago

Yes the medium motor is connected to "A". I can also verify it via the Device Browser -> Motors menu. It shows the medium motor on A and two large motors on B and C.

Here is the visual code: ev3-medium-motor-test

Here is the robot configuration, matching the Track3r: ev3-medium-motor-conf

Here is the Python code, using "Show code":

    #!/usr/bin/python

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

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

    def run():
        hal.rotateRegulatedMotor('A', 30, 'rotations', 1)

    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()

The _brickConfiguration looks surprisingly empty, I would expect that it would contain the sensor and actuator configurations I've set in the Open Roberta UI.

ensonic commented 7 years ago

Yes, that's the problem. I'll take a look where the motor is lost.

ensonic commented 7 years ago

This looks better:

_brickConfiguration = {
    'wheel-diameter': 5.6,
    'track-width': 18.0,
    'actors': {
        'A':Hal.makeMediumMotor(ev3dev.OUTPUT_A, 'on', 'foreward', 'none'),
    },
    'sensors': {
    },
}

This will be fixed with the next server release.

osma commented 7 years ago

Wow, that was quick! Thanks!