Skip to content

Error when a motor is left unused after program containing a function definition terminates #195

Closed

Description

@ndward

A very weird observation. I get the impression that if I have a program that includes a function definition AND the program does not use all the motors that have been declared then I get an error. If the function definition is not there: no error. If the motor(s) gets used: no error. What's going on? Simple (and pointless) example:

gives me no error:

from time import sleep
import ev3dev.ev3 as ev3
#m = ev3.LargeMotor('outB')
def myfunc():
    sleep(2)
sleep(1)

gives me an error:

from time import sleep
import ev3dev.ev3 as ev3

m = ev3.LargeMotor('outB')
def myfunc():
    sleep(2)  
sleep(1)

no error:

from time import sleep
import ev3dev.ev3 as ev3
m = ev3.LargeMotor('outB')
def myfunc():
    sleep(2)
sleep(1)
m.run_timed(duty_cycle_sp=-50, time_sp=1500)
sleep(5)

no error

from time import sleep
import ev3dev.ev3 as ev3
m = ev3.LargeMotor('outB')
sleep(1)

See also my comment at the bottom of this page https://sites.google.com/site/ev3python/learn_ev3_python/keyboard-control. What's going on?

Activity

  1. WasabiFan commented on Sep 4, 2016

    @WasabiFan
    Member

    What is the error that is printed? I suspect that I know what is going on, so I should be able to take a look in half an hour. Also, can you use the "edit" button next to the title to give this issue a more descriptive name (e.g. "Error when a motor is left unused after program terminates")?

    Thanks for the bug report!

  2. changed the title [-]Weird[/-] [+]Error when a motor is left unused after program containing a function definition terminates[/+] on Sep 4, 2016
  3. ndward commented on Sep 4, 2016

    @ndward
    Author

    When I run this:

    from time import sleep
    import ev3dev.ev3 as ev3
    m = ev3.LargeMotor('outB')
    def myfunc():
    sleep(2)
    sleep(1)

    I get
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 281, in del
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 730, in stop
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 295, in command
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 216, in set_attr_string
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 204, in _set_attribute
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 88, in write
    File "/usr/local/lib/python3.4/dist-packages/python_ev3dev-0.6.0-py3.4.egg/ev3dev/core.py", line 74, in file_handle
    NameError: name 'open' is not defined

  4. WasabiFan commented on Sep 4, 2016

    @WasabiFan
    Member

    Ah, yes; this is an easy fix. I'll fix it up now.

  5. ndward commented on Sep 4, 2016

    @ndward
    Author

    Thanks! What do I have to do to benefit from your fix?

  6. WasabiFan commented on Sep 5, 2016

    @WasabiFan
    Member

    Actually, this has already been fixed as it turns out. The problem is that the version of this library is a pretty old one, which was published before the changes were made to migrate to Python 3.

    Can you check what ev3dev version you are running by looking under "About" in Brickman? If the "Kernel version" ends in -10-ev3dev-ev3, -11-ev3dev-ev3, -12-ev3dev-ev3, -13-ev3dev-ev3 or -14-ev3dev-ev3, you can get my changes (and all the others since the version of ev3dev-lang-python that you are using) by running sudo apt-get install python3-ev3dev. Then just make sure you are running your code with python3 instead of python.

    If you are running an older version, this will be harder. Tell me if that's the case and we can figure it out.

  7. ndward commented on Sep 5, 2016

    @ndward
    Author

    Brickman About says I am using Brickman v0.7.2 and Kernel ...-9-ev3dev... so I am running sudo apt-get install python3-ev3dev and expecting many of my problems to disappear. I'm surprised my setup is so outdated because I only started using ev3dev a month ago. I assume I should run sudo apt-get install python3-ev3dev regularly so as to be sure of having the latest version?

    Oops. I get an error when I run your sudo code (I tried thrice):
    robot@ev3dev:$ sudo apt-get install python3-ev3dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
    python3-ev3dev
    0 upgraded, 1 newly installed, 0 to remove and 108 not upgraded.
    Need to get 27.1 kB of archives.
    After this operation, 186 kB of additional disk space will be used.
    Err http://ev3dev.org/debian/ jessie/main python3-ev3dev all 0.7.0
    rc1
    Temporary failure resolving 'ev3dev.org'
    E: Failed to fetch http://ev3dev.org/debian/pool/main/p/python-ev3dev/python3-ev3dev_0.7.0~rc1_all.deb Temporary failure resolving 'ev3dev.org'

    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

  8. dlech commented on Sep 5, 2016

    @dlech
    Member

    1.You need to be connected to the Internet and you need to run sudo apt-get update first.
    2 python3-ev3dev will not work with -9-ev3dev kernel. Well, at least motors won't work right.
    3. We have more up-to-date image files that have the most recent version of everything pre-installed here. We haven't been advertising them as the recommended image because of some serious issues. However, the 2016-09-04 image we just published yesterday is pretty good, I think - obviously it hasn't been widely tested yet.

  9. ndward commented on Sep 5, 2016

    @ndward
    Author

    I am sure that I have an SSH connection brick to PC and a working connection between the PC and internet. Is it possible to have both of these and yet not have a connection from the brick to the internet? I've restarted my SSH program (MobaXTerm) but still have the same problem. Can I assume that an easy way to check whether I have an internet connection to the brick is to runping "www.google.com" ? This gives me an error ping: unknown host www.google.com

  10. dlech commented on Sep 5, 2016

    @dlech
    Member

    Yes your test is valid. You can also goto "Wireless and Networks" on the brick itself. If it says Status: Online, then you have an Internet connection. If it just says Status: Connected, then you don't have an Internet connection.

    Try restarting Internet Connection Sharing in Windows and reconnecting.

  11. ndward commented on Sep 5, 2016

    @ndward
    Author

    If it says 'Connected' it means I am NOT connected to the internet? This could be clearer!!!

    Because I was having these problems while using a WiFi connection I re-established a USB connection. Right now my brick says I am Online via WiFi and Connected via USB. And the ping test does not work. What happens when one has more than one connection simultaneously? Bad idea?

    I will try restarting Internet Connection Sharing in Windows and reconnecting.

  12. dlech commented on Sep 5, 2016

    @dlech
    Member

    If it says 'Connected' it means I am NOT connected to the internet? This could be clearer!!!

    File a new issue if you think it should be changed. (at https://github.com/ev3dev/ev3dev/issues)

  13. dlech commented on Sep 5, 2016

    @dlech
    Member

    Multiple connections at one time should be OK, however you will never get two connections "Online" at the same time. Disconnect the Wi-Fi if you want to try to get "Online" via USB.

  14. ndward commented on Sep 5, 2016

    @ndward
    Author

    I turned off internet sharing in the Windows control panel, then turned it back on again. Then I disconnected and reconnected on the brick and retrieved my internet connection at last. I ran

    sudo apt-get update
    sudo apt-get install python3-ev3dev
    

    and everything went fine but About still says I have Kernel ...-9-ev3dev... as before. I rebooted the brick but still I have Kernel ...-9-ev3dev... Is there something I'm still missing?

  15. WasabiFan commented on Sep 5, 2016

    @WasabiFan
    Member

    Those commands upgraded the Python library, but ev3dev itself is still at the older version. To get a newer kernel, you can either re-flash your SD card with a recent nightly image as @dlech linked to (choose the one from yesterday here) or upgrade it in-place as follows:

    sudo apt-get upgrade
    sudo apt-get dist-upgrade

    Warning: the latter option will preserve all your files, but it takes much longer (it could be 30 minutes to an hour). Re-flashing the card is the easiest.

  16. ndward commented on Sep 5, 2016

    @ndward
    Author

    Should I assume that to stay up to date I should regularly (monthly?) run those three commands (in this order)?

    sudo apt-get upgrade
    sudo apt-get install python3-ev3dev
    sudo apt-get dist-upgrade
    
  17. WasabiFan commented on Sep 5, 2016

    @WasabiFan
    Member

    You'll need to run sudo apt-get update before those. update downloads a list of the available packages so it knows what you can install.

    Additionally, running sudo apt-get upgrade will upgrade all packages including python3-ev3dev, so you don't need the second line unless it is a new installation.

    There's a "Subscribe via Atom" button at the top of our news page that you can use to get a link to our Atom feed (an Atom feed is very similar to an RSS feed, and supported by most RSS readers). If you have a news feed reader, that's a good way to keep track of when we do a new release, and by extension when you might want to upgrade. The news posts always include any warnings about breaking changes as well.

  18. dlech commented on Sep 5, 2016

    @dlech
    Member

    If you are the kind of person that doesn't mind reporting bugs every time something breaks, then yes upgrade everything. Otherwise, my suggestion would be to only upgrade if something is not working and you think that upgrading should fix it.

    sudo apt-get upgrade upgrades all packages, whereas sudo apt-get install <package> will only install/upgrade a single package. So, for example to only upgrade the kernel, run sudo apt-get install linux-image-ev3dev-ev3. Also, you shouldn't upgrade without reading the announcements in the news section of the website. For example, by doing this you will find that you also need to upgrade the flash-kernel package when upgrading the kernel1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions