PicoBorg Revers, DC Motors and Servos

Hi again!

I was wondering if it's possible to connect 4 DC Motors (2 per channel), AND one (hopefully two?) servo on a PicoBorg Reverse, and control them separately via a GUI or PS3 joystick?
The DC motors would take care of the robot's movement and the servos are intended for on-board operations, like moving a hand or a camera.

Could this be done with only one PicoBorg? Can I make use of an Arduino here?

Kind Regards!

piborg's picture

It is possible to connect two or more motors to each output of the PicoBorg Reverse providing:

  1. You do not need to control them independently
  2. The total of their stall currents added together does not exceed the 5A limit

We do this with three motors per channel in our DiddyBorg robot.

Unfortunately you cannot really control any servo motors from the PicoBorg Reverse at the same time.
What you could do is:

  1. Connect an output pin from a 5V Arduino directly to each servo signal pin and use the servo library like this
  2. Use the GPIO on the Raspberry Pi to control the servos via some transistors (3.3V to 5V conversion) and use a GPIO library like wiringpi to output PWM levels
  3. Use a servo drive board like our UltraBorg to control the servos

Is only one BattBorg sufficient for both UltraBorg and PicoBorg, as in, can I connect them both on one BattBorg?

If I use a UltraBorg, is it possible to control the DC Motors and servos independently?

piborg's picture

It will probably depend on your servos, but there is a good chance one BattBorg would be enough.
If not what you can do is use a separate 5V supply for the servos, then the one BattBorg will be fine.

The servos and DC motors can all be independently controlled from the Raspberry Pi.

If I were to use only PicoBorg Reverse and Battborg (for the 4DC motors), and then adding an Arduino (for the servos) by connecting it from one USB on RPi, to the USB port on Arduino (thus creating a serial COM), would I be able to incorporate the servo control into, let's say, buttons or sliders on the example GUI? Would I be able to run them at the same time as the DC motors?

Is there a way to put the example GUI online, on a local server (like with Flask perhaps), so everyone who knows the RPi's current IP adress can access the GUI/control panel for controling the robot?

Thanks!

piborg's picture

The PicoBorg Reverse example GUI is written using Python with the following libraries:

  • PicoBorgRev to control the board
  • Tkinter for creating a GUI

It should be possible to add the Arduino into the mix by using the Serial library. You could then add more sliders and/or buttons to the example GUI and have them work in a similar way to the current ones.

Converting the example GUI for online use is a little more involved. Basically you would need to replace the code using Tkinter with something like Flask to make the web display. This might be a good tutorial to have a look at: https://stormpath.com/blog/build-a-flask-app-in-30-minutes

Thanks for the reply!

After already posting the question I found the diddyweb.py. How could I go about modifying this webGUI? Like adding additional buttons to turn on the PicoBorg Reverse LED for starters?

piborg's picture

Changing the Web UI is a little more complicated because it is creating the HTML code directly. Each new bit of functionality would have to be added in two places.

1. Doing the action

At the top of the WebServer class is a function called handle. This is called each time a button is pushed or a page is refreshed. What the function does is take the URL used and convert it into an action.

For example this section:

        elif getPath.startswith('/off'):
            # Turn the drives off
            httpText = '<html><body><center>'
            httpText += 'Speeds: 0 %, 0 %'
            httpText += '</center></body></html>'
            self.send(httpText)
            PBR.MotorsOff()

gets run when the off button is pressed.

You would need to add a new section with a new URL ending, for example /ledoff, which does the required task. The httpText value sent back is the text displayed under the camera image after the button press.

2. Adding the button

The buttons are also in the handle function, in the section starting with:

elif getPath == '/':

Each button is on its own line, for example the off button is:

            httpText += '<button onclick="Off()" style="width:200px;height:100px;"><b>Stop</b></button>\n'

What you would want to do is add another button line, but swap Stop for the new name and Off() with a new function name, such as LedOff().

Finally a bit further up look for the Off() function itself:

            httpText += 'function Off() {\n'
            httpText += ' var iframe = document.getElementById("setDrive");\n'
            httpText += ' iframe.src = "/off";\n'
            httpText += '}\n'

Copy these lines and change Off() for your new function name and /off for the URL ending from part 1.

If it all works you should have a new button which when pressed runs new code on the DiddyBorg :)

Really indepth! Thanks, that should do it for starters.

Do you think it's possible to incorporate ServoBlaster to control servos instead? For example, instead of a LED button, I'd have a button 'servo left', which when pressed, would rotate servo to one side for the duration of the press.
Since the library makes use of shell commands to turn a servo to a certain point, would I be able to make a button, which would in turn send commands to the Terminal? Or would I have to make use of a CGI script?

The library I'm aiming at is this one: https://github.com/richardghirst/PiBits/tree/master/ServoBlaster

piborg's picture

Running shell commands from within python is actually quite simple, so yes :)

First you will need to add the os module to the import list at the top:

import os

Now you can call the os.system function with your shell command. For example if this is your ServoBlaster command:

echo 3=120 > /dev/servoblaster

the python version would be

os.system("echo 3=120 > /dev/servoblaster")

It really is that easy!

For anyone trying the same thing, I recommend using "subprocess" module instead of "os" module. Read this for reference:
http://stackoverflow.com/questions/89228/calling-an-external-command-in-...

So instead of doing:

os.system("echo 0=100% >/dev/servoblaster")

You do:

subprocess.call("echo 0=100% >/dev/servoblaster")

Ofcourse, don't forget the import.

Regards!

One more thing, regarding these lines:

httpText += 'function Off() {\n'
httpText += ' var iframe = document.getElementById("setDrive");\n'
httpText += ' iframe.src = "/off";\n'
httpText += '}\n'

Is it really enough to just change Off() to Led(), and "/off" to "/led", for example? Or do I also need to change the "setDrive" ID inside var iframe in the lines above?

I'm not sure, why inside every Java function (line 2 in the above code) the getElementById is set to setDrive ID.
In my case, do I just leave the ID at "setDrive" even though I'm changing LEDs?

Hope I explaind my question well,

Kind Regards

piborg's picture

It does sound odd, but it is correct that you are getting the "setDrive" part of the page each time.

The "setDrive" element is actually the section of the page just below the camera image. This is where the values returned back from the robot are shown, which are normally speed values. Originally the name made more sense, but even the Photo function uses the same named section to take the photo. I probably should have called it something like status instead, but never mind :)

You are right though, you should be using the "setDrive" ID even for changing your LEDs or servos.

Subscribe to Comments for &quot;PicoBorg Revers, DC Motors and Servos&quot;