Controlling hobby servos

Discussion related to "under the hood" OpenMV topics.
User avatar
deshipu
Posts: 74
Joined: Sat Jan 09, 2016 5:36 am
Location: Zürich
Contact:

Controlling hobby servos

Postby deshipu » Sat Jan 09, 2016 8:51 am

I think it would make a lot of sense to have the ability to control hobby servos with the GPIO pins of the OpenMV. However, I took a look at the pyb.Servo library in the documentation, and I can see that all the pin names are from PyBoard -- there are no X1, X2, X3 or X4 pins on the OpenMV. Is that a problem with the documentation not being updated, or is that library actually not functional on OpenMV? I know I can generate the right PWM signal using timers, but it would be much more convenient to use the library.
User avatar
kwagyeman
Posts: 4430
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling hobby servos

Postby kwagyeman » Sat Jan 09, 2016 10:24 am

I need to update the docs on that. But, I've tested doing Pan and Tilt and that works. The servo control is just like you see in with the pyb module.
Nyamekye,
royoltmans
Posts: 4
Joined: Sat Mar 19, 2016 4:22 pm

Re: Controlling hobby servos

Postby royoltmans » Sat Mar 19, 2016 4:29 pm

Hi,

I am trying to get a servo to work but I just don't get it to work trough the ide v1.1 in Ubuntu and Windows.

It just crashes when I try to use the sample code:

s1 = pyb.Servo(1) # create a servo object on position X1
s2 = pyb.Servo(2) # create a servo object on position X2

s1.angle(45) # move servo 1 to 45 degrees
s2.angle(0) # move servo 2 to 0 degrees

# move servo1 and servo2 synchronously, taking 1500ms
s1.angle(-60, 1500)
s2.angle(30, 1500)

or

from pyb import Servo

s1 = Servo(1) # servo on position 1 (PB15, VIN, GND)
s1.angle(45) # move to 45 degrees
s1.angle(-60, 1500) # move to -60 degrees in 1500ms
s1.speed(50) # for continuous rotation servos

What could be the reason of this, when I try to update the unit to v1.2 nothing happens under windows.

Thanks for any response and help :)
User avatar
kwagyeman
Posts: 4430
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling hobby servos

Postby kwagyeman » Sat Mar 19, 2016 5:05 pm

Hi, have you installed the dev environment? https://github.com/openmv/openmv/wiki/F ... evelopment

Without it you can't get all the fixes we've been releasing.

Anyway, Ibrahim just released a new windows version right now: https://github.com/openmv/openmv/releases

Version 1.1 is no good. Lots of fixes since then.

When you've updated the firmware let me know if the servos working better then. If not, we can release a custom firmware image.

For updating the firmware on windows see this guide: https://www.google.com/url?sa=t&rct=j&q ... 8890,d.eWE

Put the board into DFU mode, then upload the OpenMV Cam 2 firmware that ships with the GUI.
Nyamekye,
User avatar
kwagyeman
Posts: 4430
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling hobby servos

Postby kwagyeman » Sat Mar 19, 2016 5:05 pm

If you're on Linux the firmware update in the GUI will work without needing the separate DFU app.
Nyamekye,
royoltmans
Posts: 4
Joined: Sat Mar 19, 2016 4:22 pm

Re: Controlling hobby servos

Postby royoltmans » Sat Mar 19, 2016 5:10 pm

Thanks for the quick response, I will try both routes!

I will come back to you when I am finished :)
royoltmans
Posts: 4
Joined: Sat Mar 19, 2016 4:22 pm

Re: Controlling hobby servos

Postby royoltmans » Sun Mar 20, 2016 9:04 pm

So I started with updating openmv.

I had a lot a trouble updating openmv, I tried the following to update:
- Via windows 10, Openmv-ide 1.2 failed
- Via windows 10, Openmv-ide 1.1 failed
- Via windows 7, Openmv-ide 1.2 failed
- Via windows 7, Openmv-ide 1.1 failed
- Via Vbox, Ubuntu 12 64bit Openmv-ide 1.2 failed
- Via Vbox, Ubuntu 12 64bit Openmv-ide develop version failed
- Via Vbox, Ubuntu 14 64bit Openmv-ide 1.2 failed
- Via Vbox, Ubuntu 14 64bit Openmv-ide develop version failed
- Via Vbox, Ubuntu 15 64bit Openmv-ide 1.2 failed
- Via Vbox, Ubuntu 15 64bit Openmv-ide develop version failed
- Via Ubuntu 14 on desktop, Openmv-ide developer version succesfull

Openmv-ide 1.2 ubuntu standalone doesn't work for any editions above because glibc 2.21 is used instead 2.23 (even tried a unstable vesions).

So now I am using the Openmv-ide 1.2 on windows 10 but the servo still doesnt work.
If i try this code it runs and the ide doesnt crash but my servo still doesnt respond, see the sample code below:

from pyb import Servo
s1 = Servo(1) # servo on position 1 (PB15, VIN, GND)
s1.angle(45) # move to 45 degrees
s1.angle(-60, 1500) # move to -60 degrees in 1500ms

So for the signal I tried pin pb15,14,13 and pd13,12.
I use for juice vin and gnd on the board.

Hope you can help me!
User avatar
kwagyeman
Posts: 4430
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling hobby servos

Postby kwagyeman » Sun Mar 20, 2016 9:25 pm

Hi,

The servo outputs are PD12/PD13, or pin P7/P8. Servo1 is P7 and Servo2 is P8.

The VIN pin doesn't output voltage. Its in input.

About the IDE crashes. What's the exact issue? Did the IDE not start? We'll have to fix that then. On Windows the firmware update does not work. You have to put the board into DFU mode and then use a separate tool.

This code:

from pyb import Servo
s1 = Servo(1) # servo on position 1 (PB15, VIN, GND)
s1.angle(45) # move to 45 degrees
s1.angle(-60, 1500) # move to -60 degrees in 1500ms

Will drive a Servo output on PD12 (P7).

I just tested it out and it seems to be working.
Nyamekye,
royoltmans
Posts: 4
Joined: Sat Mar 19, 2016 4:22 pm

Re: Controlling hobby servos

Postby royoltmans » Mon Mar 21, 2016 7:44 pm

The servo works, I am not sure if the output of v3.3 in vout is enough but I can use a external power source for 5v :)

Thank you for the quick responses, I can say that the new firmware works like a charm.

Kind regards,
Roy
User avatar
kwagyeman
Posts: 4430
Joined: Sun May 24, 2015 2:10 pm

Re: Controlling hobby servos

Postby kwagyeman » Mon Mar 21, 2016 7:56 pm

We'll have examples and stuff done too as soon as we can. We plan to make the example folder folder Arduino like with examples for everything. Until then, the best way to see the API is to look at these files:

https://github.com/openmv/openmv/tree/master/src/omv/py

The py_*.c files have all the function wrappers in them. Pretty straight forwards to figure our arguments.

The pyb module is from MicroPython so that's already online and documented.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 16 guests