-
Notifications
You must be signed in to change notification settings - Fork 144
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
btn=Button() gives error #193
Comments
A similar question was asked Currently you have to create an instance of the import ev3dev.auto as ev3
btn = ev3.Button()
# Is 'Left' button pressed?
print('yes' if btn.left else 'no')
# Check if any buttons are pressed:
print('yes' if btn.any() else 'no')
# Do something when state of 'Left' button changes:
def report(state):
print('pressed' if state else 'not pressed')
btn.on_left = report
while True: # This loop checks buttons state continuously, calls appropriate event handlers
btn.process() Does this work for you, or are there any errors? (I've just checked, it does work for me). |
Sorry. Errors. Because I'm using Python3? File "demidov-button.py", line 3, in |
@ndward can you check if you are missing the shebang in your demidov-button.py? The fact that "btn = ev3.Button()" is on line 3 in the traceback suggests that is the case. |
Closing...re-open if needed |
I'm back from vacation. This is my program:
and this is the error message: If I use btn = Button() instead of btn = ev3.Button() (which is right?) I get this error message: I'm using kernel 3.16.7-ckt21-9-ev3dev-ev3 You asked about the shebang but I'm running the program from the command line so the shebang should make no difference(?) |
from ev3dev.auto import *
# btn = Button() Also tried this. Which is correct? This form is the correct one. |
Thanks for quick answer. As I said in my previous message, when I use btn = Button() I get this error message: |
I am trying to reflash my ev3 with the latest nightly build to see if there is a problem with the latest published version of the library. |
Sorry, I can not reproduce this with the version that is installed with the latest nightly build. This is what I get after fresh install of nightly-ev3dev-jessie-ev3-generic-2016-09-04.img.xz (whoops, its not actually the latest one anymore, but it was half an hour ago, I promise). I followed instructions at the Getting started page. By the way, congratulations to whoever picked Etcher as the default tool, it does the job with minimum fuss! This is with python2 (python3 is not yet enforced in v0.6.0):
And this is with python3:
|
Thanks for trying. This is what I get in Python3:
I'm reluctant to work with nightly builds because I'm trying to keep things as simple as possible for beginners. |
This looks like you have a problem with the input file that is used with the |
I just upgraded the kernel from 9 to 15 (4.4.19-15-ev3dev-ev3) and have Brickman v.0.8.0. I used option 2 on http://www.ev3dev.org/docs/tutorials/upgrading-ev3dev/
I still get Thanks for your patience! |
It's worth noting that you are now using a version of this library that doesn't support the kernel version you upgraded to. You should follow the instructions at the top of the README on this repo to upgrade. Still, I doubt it will fix the button issue. |
Do you mean I should run I did that and it says 'python3-ev3dev is already the newest version.' I've spent so much time doing updates and upgrades, I suppose I really need to try working with a nightly build. Again, are there any disadvantages or risks associated with that apart from having to backup my Python files from the card to the PC? |
Yes.
Odd. I suspect the problem is related to a separate installation of the module. Re-flashing (as discussed below) will probably fix it.
No, in general they've been pretty consistently functional, and there's practically no risk of it causing any other issues; worst-case is you have to reflash. Just make sure that you back up the required files. |
Eureka (sigh). I've just copied the nightly build to a different SD card and the button code is working for me at last. I deduce that updating and upgrading does not have the same effect as using a fresh new nightly version, something that wasn't clear to me as I read the page http://www.ev3dev.org/docs/tutorials/upgrading-ev3dev/ |
I tried to flash ev3-ev3dev-jessie-2015-12-30.img.xz which is linked to from the Getting Started page. The situation is a bit different there. On a clean system, python 2 still works:
However, unlike in the nightly build, python3 version of the library is not installed out of the box.
installs version 0.7.0-rc1 for me. The
So I am at a loss. Looks like reflashing with a nightly build is the best option for now. |
@ddemidov See @ndward's comment just above yours; he got it to work by re-flashing.
Yes, re-flasing resets the card, so anything you did (good or bad) will be reset.
I can't say what it was; when in doubt, reset it.
We expect to release an official image (which will be pretty much exactly the same as the most recent nightly) within the next few days -- whenever we release v0.7.0 of this Python package. So I agree in general, but it won't be needed at this point. |
No, wait - I've just realised that now that the button code works most of my scripts involving motors no longer work! Some scripts still work. The scripts that don't work don't crash but the motors do nothing. Has something been changed in the motors? |
Did you follow the README instructions to install the right version of the library? |
This works for me on the fresh nightly build (without upgrading python3-ev3dev): robot@ev3dev:~$ python3
Python 3.4.2 (default, Oct 8 2014, 14:47:30)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ev3dev.ev3 import *
>>> m = LargeMotor('outB')
>>> m.connected
True
>>> m.run_timed(time_sp=1000, speed_sp=600)
>>> (The result is that motor turns for 1 second). |
So may be the reason is that @ndward's scripts need to be updated to the latest motor API? |
Yes, that's a good line of inquiry. @ndward Can you provide a copy of one of the scripts that isn't working? |
I ran the code suggested by Denis and it worked, so I guess I need to update all my motor scripts (grrrr). When are the APIs going to stop changing? When the APIs change in such a way that people need to update their scripts could you make it more obvious? Especially for something as basic as motors. Is there something other than motors that has changed? I'm not sure I understand WasabiFan's message about following the README instructions to install the right version of the library. I had assumed that the nightly build would simply be ready to use. Do you mean that after installing the nightly run to the card I need to do For a while I thought that this was the page to get info on the Python binding: I think this is an essential document for users of EV3 Python and that it is not conspicuous enough on your site (it is on mine!). I suggest you add a 'Languages' menu header to your site with a sub-item for each of the main supported languages. The Python sub-item should not necessarily link straight to the repo page because that page is intimidating for newbies, with a lot of stuff that is not relevant to them, it seems to me. It's a shame that the important part of that page, the readme, appears at the bottom of the page. The repo page works better than it did a month ago but as I said, I don't think the link to the Read the docs page. Similarly the page http://www.ev3dev.org/docs/libraries/ is much better than it was but again, the Get started with Python link goes to the repo page which is not very newbie-friendly. I still don't see any advice for newbies about how they can get their Python scripts onto the brick, how to run their scripts either via SSH or Brickman, and how to download scripts for the brick to the computer. I'm disappointed that you don't yet consider my site ev3python.com to be good enough to be worth mentioning near your 'get started with Python' link since that is exactly what my site is about! |
I ran |
They haven't changed in the last 7 months (aside from bug fixes and one obscure brand rename). How do you expect us to make it more clear? This is made a bit rocky by the fact that we are just getting around to releasing a new official image, but nonetheless we have a news feed which lists all breaking changes and you can subscribe to it to stay up-to-date. This will be better once we have gotten a new image released, which as I said before should be happening in the coming days.
http://www.ev3dev.org/news/2016/04/11/Kernel-Release-Cycle-10/
It is, but not at a version that is fully supported; so you do have to run those commands to get the newest version of the library. Why? I can't speak to this specific case, but in general the external libraries aren't synched with kernel releases, so having everything be packaged together and up-to-date is difficult for nightlies, and it isn't even a significant problem when the solution is a one-time command. This is the only language library that is shipped with the image; if you are using JavaScript or C++ or Java or any of the other languages, you have to install it yourself -- that's just a required part of software development in general. We try to make Python easiest to use because it is the most popular, but at some point we have to accept that we won't be able to keep them in sync for nightly builds.
Yes, I believe the latter is correct (@ddemidov ?).
What site? ev3dev.org is about ev3dev as a platform, not about Python specifically; once you get to this repository, however, you are referred to those docs. There's a link in the title and a link in the "User Resources" section, and that section is linked to by the getting started area and other places. What do you believe would make the README clearer?
That's an interesting idea. I'm hesitant to do that immediately, but I will definitely consider it; we're currently working on some major structural changes to the site, so that might be something we do as well. As for the issue with the README, I don't think we can do much better. Everything in this README is relevant to a beginner; there is a getting started guide, some examples, documentation links, etc., and all of those are things that every user should see. I'm unsure of how we could make this easier for new users without compromising the overall usability and functionality, even if we created a dedicated page for it.
This doesn't happen over night. We have an SSH page that is currently awaiting review and a bunch of other changes in various stages of completion. We're working on it, but right now there are still holes as you saw a month ago.
I've discussed this via email. In short, I don't want to rely on your site because we can't be confident that it won't disappear or change drastically -- it's not because we don't like it. It might make sense to link to it from the repo README, though even then it's a significant risk.
I'm not sure exactly what you mean. Can you tell us the exact image you flashed from, the kernel version that it says you are using, and the output of the following commands?
|
I can confirm this. The latest available version of
That is correct, the latter link is the one that is autogenerated with every commit into this repo. @rhempel is the owner of the former, so I guess it was an experiment of his. @rhempel, do you think you could delete the project on readthedocs?
My guess is the following happens: if you tried to run my example m.run_timed(time_sp=1000, speed_sp=600) it is equivalent to m.time_sp=1000
m.speed_sp=600
m.run_timed() The m.run_timed(time_sp=1000, duty_cycle_sp=100) the motor will turn, but not because you've set >>> m.run_timed(time_sp=1000, speed_sp=600) # should turn
>>> m.reset()
>>> m.run_timed(time_sp=1000, duty_cycle_sp=100) # should silently fail
We could link to @ndward's site from the README. We could even incorporate the pages from that site into our documentation on readthedocs. Although I am not sure if @ndward would agree, or how much work it would involve (my guess is not that much). But I guess this would also answer @WasabiFan's concern about stability of @ndward's site. @ndward, what do you think?
The latest nightly images are good as is, there is no need to install/upgrade anything. I guess you are talking about my experiment with the officially released image, where I had to install |
Hi, and thanks for your long comments. I downloaded nightly-ev3dev-jessie-ev3-generic-2016-09-22.img. I have kernel 4.4.19-15-ev3dev-ev3. robot@ev3dev: My EV3 motors are behaving strangely at the moment. Yesterday, for example, the standard remote control script (which worked perfectly a couple of days ago with the old card) would only make the motors turn forwards, not backwards. I restarted the brick and now the same script does not turn the motors at all. The script below
fails to turn the motor with turns the motor with duty_cycle_sp=50 but does turn the motor with speed_sp=-600. Output is as follows: I don't really understand the reason you give for not wanting to link to my site: "I don't want to rely on your site because we can't be confident that it won't disappear or change drastically -- it's not because we don't like it. It might make sense to link to it from the repo README, though even then it's a significant risk." Surely if my site were to evolve in a way you didn't like you would just remove the link. Where is the "significant risk" and does it really override the potential benefit of giving EV3 Python beginners access to dozens of simple code samples, just what your own site is currently lacking? There isn't much risk of my site disappearing for it's hosted free by Google and if there is one company in the world that is unlikely to disappear then that could well be Google, wouldn't you agree? |
The symptoms convince me in my earlier assumption: your duty_cycle_sp |
I think I understand what you are saying. I probably reset the motors at some point, in effect disabling the duty_cycle_sp argument until speed_sp is given a new non-zero value.
I get this output |
(Off topic, I know). There is a section on the remote control on this page |
I found the parameter max_speed and can thus answer my own question above about the range of values of speed_sp for the standard EV3 motors: Medium Motor has max_speed= 1560 and Large Motor has max_speed=1050. Since these motors are the standard motors perhaps it would be worth mentioning these values in the documentation for max_speed? Similarly it would perhaps be worth mentioning in the documentation for count_per_rot that count_per_rot=360 for both the standard EV3 medium motor and the standard EV3 large motor (thus one count = one degree of course) I understand the values for max_speed given above are theoretical values so for convenience it might make sense to limit actual used values to 1500 and 1000? |
So currently, motors are always controlled by
Opened new issue: #214. |
You're right, I missed that announcement about kernel 10. The getting started section of ev3dev.org still proposes the 2015-12-30 pre-release which includes version 9 of the kernel, I believe, which is what I was using until very recently. I probably won't be the only one getting confused over the changes to the motor commands until a new pre-release is proposed on the getting started page. |
I found this tip very helpful: "So currently, motors are always controlled by speed_sp parameter except for the run_direct() command. Basically, you should never set duty_cycle_sp and always use speed_sp" and I'm surprised to see that that tip is not included on http://www.ev3dev.org/news/2016/04/11/Kernel-Release-Cycle-10/ |
I've studied the documentation for speed_sp but still have some questions.
As I understand it, the difference between run_direct and run_forever is that run_direct is unregulated and uses duty_cycle_sp while run_forever is regulated and uses speed_sp? If I set a value for duty_cycle_sp (with or without actually running run_direct) this should not interfere with the other (regulated) commands, should it? Can you confirm that if you run the run_forever command then changing speed_sp while running will NOT take effect immediately? |
I would like to make sure I give the right advice to users who have kernel version 9 and therefore need to upgrade. I will recommend that they use option 1 (reflash SD card) on http://www.ev3dev.org/docs/tutorials/upgrading-ev3dev/ but I understand this only gives an upgraded version of EV3dev and that they need to upgrade the Python binding also. Please confirm that all that needs to be done to get the latest Python binding is
Specifically I would like to be reassured that it is NOT necessary to run the code below:
|
It is, although it is worded differently; it's the first "breaking changes" bullet point. You should read the motor tutorial if you want to make sure you understand the various properties (the guide explains using the command line, but it applies to what you are doing too). It also may be helpful to look at the tacho motor detailed docs.
No. The
As mentioned above, the duty cycle and speed values do not do the same thing, and can't be compared like this. Additionally, if I remember correctly, the values in EV3-G correspond to the functionality of
Because the units don't correspond like that, I don't believe this makes sense. Additionally, I don't expect that it would "misbehave", per se. It would just apply full power (100% duty cycle) without being able to get to its target speed if you gave it one that was unattainable.
By giving it a negative speed there, you're telling it to go to forward 360 degrees by rotating backwards... that doesn't make much sense 😆 The negative sign is ignored with
Correct; the duty cycle is completely ignored unless you use
Correct.
It turns out that I was incorrect; if you re-flash, you don't need to run either of those sets of commands. It should "just work" (correct, @ddemidov?).
Yep, exactly. Same with |
Correct, python3 version 0.7.0-rc1 of the library comes preinstalled. |
Hi. I've just made a website, ev3python.com, to help beginners make a start with EV3 Python (when I say 'beginners', I mean people who have a basic knowledge of standard Python but no knowledge of EV3 Python). I'm pretty much a Python beginner myself, despite being a teacher of computer science. I find EV3 Python to be quite neat and I've got most of the robot-specific functions worked out but not all of them. My biggest problems are with the EV3 buttons and the LCD. I've been advised to open one issue page per problem so let's start with the EV3 buttons.
I've come across many EV3 Python programs that include the detection of button presses but they all fail for me at the line btn=Button() . I get NameError: name 'Button' is not defined. Is it just me? Is there a bug? There is an example of button code on http://www.ev3dev.org/docs/tutorials/using-ev3-buttons/ but it's far too complicated: 25 lines of code just to detect a button press? There must be a better way? Please help! Can someone post a simple program showing good button code?
The text was updated successfully, but these errors were encountered: