Simple Script or manual to control the motors
Forums:
Hi,
there are excellent python scripts to control the robot. I'm not a python profi progammer, so the python sricts are not easy to read/unterstand for me. Is there a manual or a simple commented python script (simple start/stop the gear motors) available which helps to start own programming.
Many thx in advance
Peter
piborg
Sun, 08/13/2017 - 14:37
Permalink
Simple example
Below is a very basic example of controlling motors from the ZeroBorg.
In the comments below forwards / backwards refers to the ZeroBorg output. The motors may run the opposite way depending on the wiring.
The
maxPower
calculation is not strictly necessary, however running the motors over their intended voltage is not recommended.peter.demharter...
Sun, 08/27/2017 - 17:06
Permalink
Cool thx :-)
many thx souds cool ..
duckstar
Wed, 04/11/2018 - 12:42
Permalink
Hi
Hi
Just trying this and its doesn't work.
Code is below. It just starts waits 10 seconds and returns to prompt. Any Ideas?
Thanks
Nic
import ZeroBorg
import time
ZB = ZeroBorg.ZeroBorg()
ZB.Init()
ZB.ResetEpo()
maxPower = 6.0 / 8.4
ZB.SetMotors(0.5 * maxPower)
time.sleep(10.0)
ZB.MotorsOff()
piborg
Wed, 04/11/2018 - 15:30
Permalink
No movement
There are a few different reasons that could explain why the motor(s) are not moving:
We can help narrow the problem down, it is probably something simple to fix :)
duckstar
Wed, 04/11/2018 - 16:05
Permalink
Hi
Hi
I have another program that works fine though, using a controller.
The robot moves well, using that. It has I'm using this kit - https://www.core-tec.co.uk/tiny-4wd/
It is currently plugged into mains supply but I will be using a 9V battery.
No error message comes up, it shows that the board has been detected, waits 10 secs, then ends.
Thanks
Nic
piborg
Wed, 04/11/2018 - 16:44
Permalink
Other code
Can you give us a link to the code you are using which works?
My best guess is that the other code is doing something which is needed to make the robot move.
duckstar
Wed, 04/11/2018 - 21:27
Permalink
Hi its your pre-loaded code
Hi its your pre-loaded code for the zeroborg. (ZBjoystick.py) I have made some small tweaks but it is basically the same.
piborg
Thu, 04/12/2018 - 11:26
Permalink
Power supply
You mentioned above that the robot is only powered by a mains supply at the moment.
Do you mean that the Raspberry Pi is being powered by a USB mains charger and no other power is supplied to the ZeroBorg itself?
duckstar
Thu, 04/12/2018 - 16:02
Permalink
Hi, it the Zeroborg is
Hi, it the Zeroborg is connected to the Pi Via the GPIO pins. So is powered that way, the red light comes on on the Zeroborg. As I said before if I run the ZBjoysick program it works fine, it is also plugged in at the moment via USB still, but I have had it running on a 9 Volt battery as well.
What version of python should it being run in ?
Thanks
piborg
Thu, 04/12/2018 - 19:16
Permalink
Try this code
While the ZeroBorg logic does get power from the GPIO (hence the LED flash), the motors will only take power from the battery connection. You will need a battery attached to the ZeroBorg for the motors to turn.
If you can try this code example with the battery attached it should behave the same way as the
zbJoystick.py
example when driving forwards at full speed:If your tweaks modified the
driveLeft
/driveRight
lines above you should make the same changes.Our examples are tested with Python 2, which is the version loaded by default on the Raspberry Pi when you run
python
from a terminal.duckstar
Thu, 04/12/2018 - 21:18
Permalink
Hi
Hi
Thank for this I'll try it tomorrow.
Why does the basic code not work then?
But also the when i'm running the normal zbJoystick.py file, the robot moves fine when attached to mains power. (I was testing it) I have nothing attached to the zeroborg and I have been running it with a power pack attached fine. So I don't understand "the motors will only take power from the battery connection. You will need a battery attached to the ZeroBorg for the motors to turn."
Thanks again for all your help.
Nic
duckstar
Sun, 04/15/2018 - 17:32
Permalink
Hi
Hi
Just tested this. Sorry been busy.
Tried the above, with a 9V battery attached, not on mains power, and it behaves in the same way.
Wheels turn for about a second, then after 10 seconds the script ends.
The following message is displayed.
Loading ZeroBorg on Bus 1, address 40
Found ZeroBorg at 40
ZeroBorg loading on bus 1
Then after 10 seconds the prompt returns.
Thanks
Nic
piborg
Mon, 04/16/2018 - 17:44
Permalink
Motors turning off early
It sounds like the problem is that the motors are being turned off outside of the script rather than an issue with the script itself.
Having had another look at the
zbJoystick.py
script it enables the failsafe on the ZeroBorg which turns the motors off unless it receives updates from the Pi at least twice a second.To fix the problem you can simply turn the failsafe off in the script. Try this version:
If that works you should be able to add this line after the
ZB.Init()
in your original code and get it to work as well:duckstar
Wed, 04/18/2018 - 08:35
Permalink
Thanks that script you have
Thanks that script you have show does work.
It doesn't quite work with my more complex script but it works well enough.
It will run forward but won't stop, you have to EPO reset to get it to stop.
I will post my full code later to see, though.
Thanks
Nic