I have a Zumo 2040.
It has been operational and working as expected for a few weeks.
This problem is new!
I am trying to run the proximity_demo.py program from the downloaded zip file that contains all the sample programs. I am using Thonny.
I get the following error:
Traceback (most recent call last):
File “”, line 30, in
AttributeError: ‘ProximitySensors’ object has no attribute ‘total_counts’
Line 30 is
if proximity_sensors.total_counts() > 0:
NOTE: The proximity_demo.py that is built into the Zumo does work correctly.
I have reinstalled Thonny
I have deleted and unzipped the demo program file
The 'total_counts" IS in proximity_sensors.py, line 129
Other demo programs work as expected - I haven’t tried them all.
This might be another clue although it seems totally unrelated.
When I first received the robot, I was able to use PuTTY with the Zumo,’
Even that doesn’t work now.
I am not sure how you could have been trying to run a program with Thonny from a compressed file; I tried it and Thonny could not even open the file. In general we anticipate most users will save and run programs on the Zumo 2040 by accessing the code through the drive that should appear when you connect the robot and occasionally back up the files to a computer. However, it sounds like you are trying to run the programs from your computer. What is the reason for that? If I am misunderstanding, can you clarify what you are trying to do?
Thank you for the quick response.
Sorry for the misunderstanding
The files are all unzipped.
I am editing and loading the files to the Zumo using Thonny.
So
All the files are unzipped from the downloaded zip files.
I open the files with Thonny and then try to load them to the Zumo.
All the files I have tried up to this point work just fine.
It is just this file that gives an error.
This is the first file using the proximity sensor that I tried to load into the Zumo from Thonny.
The files that are preloaded in Zumo work fine - no problem.
It seems that Thonny cannot find the proximity_sensors.py file.
If the files you are unzipping are from the micropython_demo folder of our Zumo 2040 repository on GitHub, then those should be identical to the files that we load onto the Zumos. (Correction in later post.) The only way I have been able to reproduce your particular error message has been to directly modify the proximity_sensors.py file saved on my Zumo 2040, so I suspect something like that might have happened here.
Could you back-up what you currently have saved on the robot and try restoring your Zumo software to its factory state by following the “Upgrade instructions” at the end of the “Updating the MicroPython firmware” section of the Zumo 2040 user’s guide?
First, I am just learning micropython or even python!
I keep thinking I am compiling a program and then loading it into zumo, but that is not what happens. It’s more like running a Basic interpreter!
All the files I need MUST be on zumo, not my computer.
So here is what I am seeing. ( I am following the instructions from the Pololu Zumo 2040 Users Guide web page.)
I downloaded a file named: zumo-2040-robot-master.zip and unzipped it.
In the micropython_demo folder, it has proximity_demo.py.
On the zumo there is also a program proximity_demo.py.
These are not the same.
In both the zipped file I downloaded and the zumo there are files named proximity_sensors.py.
These are not the same.
The error I get indicates that Thonny is using the proximity_sensors.py from the zumo, not the one from the downloaded file.
And That Is My Problem! The program needs the proximity_sensors.py that is on my computer.
Is there a way to just load a new program into the zumo?
SO - If you have any helpful hints to get me back on track - that would be great.
In the mean time, I will do as you suggest and learn about Upgrading the Micropython Firmware.
It sounds like you are getting closer, but there are a couple of details I’d like to clarify. The only place that I think you would find the file zumo-2040-robot-master.zip is in the Zumo 2040 repository on GitHub. (We do not have a direct download link for that in the user’s guide.) If that is not where you are downloading that file from, can you please post a link to where you actually found it?
For the two files we have discussed, proximity_demo.py and proximity_sensors.py (and I expect all of the other micropython files, though I have not checked them all myself recently), the versions from the GitHub repository and the versions we load on the robots during production are identical. So, if you are seeing differences between files that we expect to be identical, then at least one of them was probably modified (or maybe corrupted) at some point. Correction in later post.
Stashing redundant or old files that you are uncertain about and no longer using somewhere out of the way on your computer (and to consider for deletion later) in addition to my earlier suggestion to restore the Zumo to its factory settings should help clear things up.
The version that was on my zumo when I received it was the Nov 2023 version. I did not update it to the latest version until last night.
That was problem number 1 and number 2 was my misunderstanding that I was NOT compiling - micropython is not a compiled language - I got it NOW!!
As of last night after I upgraded the zumo to the 2024 sfwr, all is good.
A couple of practical questions
Where can I find definitions for the commands such as display.poly? Some are obvious such as .show and .fill, or definitions for any “tool” so I can understand and not guess about the command function.
Where do I find machine as in from machine import Pin, SPI and other things like that. I understand some are in the standard Python library and I can find them.
Where do the magic numbers come from such as max_speed = 6000, kp = 350, kd = 7 in gyro_turn.py? Are there other magic numbers?
Sounds like the demo from the zip might be outdated compared to the firmware. I’d check that the proximity_sensors.py in the zip matches the one on the Zumo 2040—sometimes methods change between versions😁
I am glad to hear that it seems to be working now!
I made a mistake earlier and was not correctly comparing the software posted on GitHub and in the user’s guide to what we are actually loading on the robots during production. In production we have been loading an older version of the software that had different code for using the proximity sensors, including not having the total_counts function which combined with mixing up the files explains the issues you were having. I will edit my earlier post to reflect this. Regardless though, as a general guideline, backing up your programs somewhere out of the way and updating the robot’s firmware by following the instructions in the user’s guide is a good starting point to troubleshoot problems like these.
The machine library is built into MicroPython. (It is specific to MicroPython and not part of Python). You can find more information it in MicroPython documentation.
It is probably not practical to go over where all of the numbers in our Zumo software come from, but you are welcome to ask about the ones you are working with and that you are unable to figure out from reviewing the code and comments in it.
max_speed being 6000 makes the full range of motor speeds (0-100%) available, so you can reduce it if you want the maximum motor speed to be lower, but increasing the value will not increase the maximum motor speed. You can look at zumo_2040_robot\motors.py to see how the motor functions work.
kp and kd are the PID (Proportional–integral–derivative) controller constants. (gyro_turn.py does not use an integral term.) In our example programs that use PID control, the default values that should generally work okay based on our experimentation, but there might be room for optimization depending on your particular robot and what you specifically are aiming to achieve (i.e your desired tradeoff between responsiveness and accuracy).