PS3 Setup

Hi Guys,
My kit arrived today, very fast indeed, thank you.
I have been running through the pre build setup of my pi and have come across the following problem.
I think you would have a better insight if I paste, rather than try to explain, so here it is ...

pi@raspberrypi ~ $ hciconfig
hci0:   Type: BR/EDR  Bus: USB
        BD Address: 00:15:83:0C:BF:EB  ACL MTU: 339:8  SCO MTU: 128:2
        UP RUNNING PSCAN
        RX bytes:1414 acl:0 sco:0 events:52 errors:0
        TX bytes:446 acl:0 sco:0 commands:45 errors:0

pi@raspberrypi ~ $ sudo apt-get install pyqt4-dev-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
pyqt4-dev-tools is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
pi@raspberrypi ~ $ wget http://www.pabr.org/sixlinux/sixpair.c
--2015-04-29 20:55:10--  http://www.pabr.org/sixlinux/sixpair.c
Resolving www.pabr.org (www.pabr.org)... 62.210.16.61
Connecting to www.pabr.org (www.pabr.org)|62.210.16.61|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4022 (3.9K) [text/x-csrc]
Saving to: `sixpair.c.4'

100%[======================================>] 4,022       --.-K/s   in 0s

2015-04-29 20:55:10 (20.7 MB/s) - `sixpair.c.4' saved [4022/4022]

pi@raspberrypi ~ $ gcc -o sixpair sixpair.c -lusb
sixpair.c:23:17: fatal error: usb.h: No such file or directory
compilation terminated.
piborg's picture

There are some dependencies you need to install before building sixpair.

Try running the following lines:
sudo apt-get install bluez-utils bluez-compat bluez-hcidump
sudo apt-get install libusb-dev libbluetooth-dev joystick

That did the trick, thank you.
Today is wiring day, gotta go get new wire strippers first.

I have been wondering, how is the Rpi shut down when running in remote mode with the PS3 controller?
Obviously just pulling the plug is not ideal.

piborg's picture

We generally use one of three methods to shut the Raspberry Pi down:

  1. Simply pull the plug:
    While not ideal it does not tend to cause problems, you will have the same effect if the batteries become flat
  2. Shutdown via SSH:
    Fairly simple, does require either a wire or wireless network connection to the DiddyBorg though
  3. Add a button press to the script(s):
    This is easy to add in, we use select for this normally

If you wish to add a shutdown button to the script you will need to add the two highlighted sections below.
The line numbers / code lines are based on diddyJoy.py:

# Settings for the joystick
axisUpDown = 1                          # Joystick axis to read for up / down position
axisUpDownInverted = False              # Set this to True if up and down appear to be swapped
axisLeftRight = 2                       # Joystick axis to read for left / right position
axisLeftRightInverted = False           # Set this to True if left and right appear to be swapped
buttonResetEpo = 3                      # Joystick button number to perform an EPO reset (Start)
buttonSlow = 8                          # Joystick button number for driving slowly whilst held (L2)
slowFactor = 0.5                        # Speed to slow to when the drive slowly button is held, e.g. 0.5 would be half speed
buttonFastTurn = 9                      # Joystick button number for turning fast (R2)
interval = 0.00                         # Time between updates in seconds, smaller responds faster but uses more processor time
buttonShutdown = 0                      # Joystick button number to get the Raspberry Pi to shutdown (Select)

# Power settings
voltageIn = 12.0                        # Total battery voltage to the PicoBorg Reverse
voltageOut = 6.0                        # Maximum motor voltage
                # Check for button presses
                if joystick.get_button(buttonResetEpo):
                    PBR.ResetEpo()
                if joystick.get_button(buttonSlow):
                    driveLeft *= slowFactor
                    driveRight *= slowFactor
                if joystick.get_button(buttonShutdown):
                    # Start the Raspberry Pi shutdown sequence
                    print 'Shutting down...'
                    PBR.MotorsOff()
                    PBR.SetCommsFailsafe(False)
                    PBR.SetLed(True)
                    os.system('sudo halt')
                    break
                # Set the motors to the new speeds
                PBR.SetMotor1(driveRight * maxPower)
                PBR.SetMotor2(-driveLeft * maxPower)

Now when you press select on the controller:

  1. The motors should stop
  2. The LED on the PicoBorg Reverse should come on
  3. The Raspberry Pi starts to shutdown
  4. The script terminates
  5. The Raspberry Pi indicates it has finished shutting down

You can find the PS3 button numbers on our PS3 controller setup instructions page if you wish to use a different button.

Thank you, I will implement the button shutdown over the weekend ... and a switch too.

In the meantime, my build is complete and it worked flawlessly on the first test, which is clearly a testament to your code and support.
I then swapped to the PS3 code ... and that works too.

I have 10 x 1.2v rechargeables rated at 2000mah. How long should it run on these?
Obviously there are are many factors to consider, I'm only wondering if you could offer a guide?

This is just the start of my foray into Python, it will be the basis of a lot of learning for me.
Ultimately I want to build something like your DoodleBorg, I have most of the skills required, except for Python, so I figured I should start small-scale :-)

piborg's picture

Glad to hear your build went well.

As you say how long he will run for depends on what he ends up doing.

If he is moving around most of the time we tend to get between one and two hours.
If he is sat still most of the time we found he lasts about 10-15 hours with just a B+, camera and bluetooth.
We usually use 10x 1900 mAh AAs, so you should see very similar times.

The script we use to run DoodleBorg at the moment is actually very similar to the example provided for DiddyBorg.
The only major changes are that he uses 3x Diablo boards instead of 1x PicoBorg Reverse.
When we write any new code to run on DoodleBorg we test the logic on a smaller robot first to be safe.

Thank you yet again,

I will be on the lookout for some motors to build a DoodleBorg, I understand from your video that you used motor cycle starter motors? I guess they all have to be identical do they?
Would it be feasible to just use 4 motors/wheels? Would the steering still work ok, or would there be too much strain on the axles?
Again from your video, the gearing ration looks to be very high?
As I'm sure you have noticed, I am a very much a novice ... Having never attempted anything like this before, but you have certainly instilled a serious urge to make it happen.
Another added bonus is that I will gain a ton of experience, either that or I would have to admit defeat ... Not gonna happen.

I was at the Brighton Maker Fair last year and saw an RC road cone that perked my interest, it would be great if I could have something worth showing this year ... maybe thats a little too optimistic, even for me :-)

BTW; The shutdown command works great
A couple of pictures is the least I could do

Images: 
piborg's picture

We used starter motors, however you could equally use motors intended for:

  • Electric scooters
  • Powered wheelchairs
  • Mini ATVs

We simply picked something we could get six of with a decent amount of power (W).

If they are connected in the same way we have they should all be the same.
If they are not it is very likely the "slower" motors will be pulled by the "faster" ones, which is very inefficient.

We did not actually try four motors, but I suspect the steering may struggle.
When he turns the middle two wheels do most of the work, the front and back are mostly just "breaking traction".
You could try removing the centre motors from DiddyBorg to see how he copes, carpet would make a good approximation of rough ground.

We made the gearing high for two reasons:

  1. Increased torque, which allows us to pull more weight
  2. He is scary enough at full speed as it is, lower gearing would make him move faster

If you take the RPM of the motor and your wheel measurements you can work out the theoretical top speed of the wheel.
This theoretical top speed is a bit above how fast the wheels should go when lifted off the ground, the heavier your robot is the further his real top speed will be below this value.
You can then take this number and work out a reasonable gearing ratio.

Our aim with DoodleBorg was raw pulling power :)
It would be great to see another large Raspberry Pi robot, especially if it has something special about it.
The main problem we had was expense, mostly because of the heavy weight he moves around.
If you make a lighter one you would be able to get away with lower power motors with lower gearing.

Thanks for the photos, I think your Velcro battery strap is a great idea.

Thanks for the ideas, I don't have a 'use' for him. I simply want to build him, so this gives me a free reign on the motors ... and everything else too for that matter :-)
Though I would like to be able to sit on it and drive around.
I'm thinking maybe windscreen wiper motors perhaps, I'm sure I will come across something suitable. Like you, the availability is probably going to be the boss on this one, and price to a lesser extent.
What do you think would be the minimum wattage I should aim for? I'm happy to compromise, but don't want to build it and find that it's under powered.

I see what you mean, of course the motors have to be all the same ... I should have thought about that before asking. Doh!

Your explanation 'breaking friction' got my head around that one too, cheers. Four motors are going to put far too much strain on everything I think.

I do want to put LEDs on my DiddyBorg. I've built a 400 pixel LED matrix controlled with Arduino.
https://www.youtube.com/watch?v=oiXbXCQdf8c
I have been playing with this today https://learn.adafruit.com/neopixels-on-raspberry-pi/overview
and even managed to get it working.
My hope is that I will be able to put 2 strips on the top (one either side) and have each strip scroll in the same direction as the wheels on that side.
With my limited knowledge of Python, it may be a very tall order, but I'm gonna give it me best shot.

The velcro came into play because I found the zip tie a little fiddly for me, glad you approve.

piborg's picture

Depending on how slow you will make the robot you may find windscreen wiper motors are a bit too heavily geared internally.

With regards to how much power it all depends on how heavy the robot is overall.
With the weight we have I would imagine 200 W each would have probably sufficed if we did not care about towing.
The awkward point is that more powerful motors also tend to be a bit heavier.

An important consideration is where you intend to actually run the robot.
In our case DoodleBorg is too big and fast to really run around your average back garden.
In truth we actually find it quite hard to find places we can run him freely, usually we resort to empty car parks and similar places.
If you make a smaller one (say 1/2 the size) you will find more places to be able to run.

Since both size and weight limits will reduce the available options for motors I would suggest you get a rough idea of how big and heavy you want him to be quite early.

The LEDs are a great idea.
You may need to do some threaded code in Python so that the LED operation and movement operation run along side each other, but it should not be too difficult to have both in the same script.

Yet again, you have far excelled in your reply. You clearly have a knack for pre-empting my potential requirements and potential problems.

I am going to have a tour around and look for motors etc and to have a chat with a friend whos workshop I'm hoping to borrow ... Fingers crossed :-)
Then I will be able to get a better idea of the size I will aim for. Thinking of where and when I can run it is a very real issue that I hadn't considered. I can be so dumb sometimes!
It does look like I will have to scale down quite a bit though.

I have never built anything with chain gearing and clearly there will also be a need for some sort of bearings for the axles to run in, and many other things I need to consider.
I will do some sketches etc and work from there, before I go buying anything. Any less is bound to see me pouring money away on stuff that I can't use.

I have always like LEDs, so have wanted to put them on my DiddyBorg the moment I saw the kit.
My coding abilities are all but non existent, from my googling of Threading python code it looks very complicated to me. But I still want to do it, so I'll keep searching and tinkering.
Yes, I will almost certainly screw up my DoodleBorg SD card ... but got it all backed up to an image on my NAS

Thanks so much for all your experienced info and guidance ... I would not have got this far without it.

Will you be going to the Brighton Maker Fair in September?

piborg's picture

Glad to help ^_^

The nice thing about software is it usually does not matter very much if you make mistakes at the experimenting stage.
I learnt how to code from tinkering with old computers like the Commodore 64, in that sense I see the Raspberry Pi as being a modern equivalent.

Threading can be a bit awkward to get to grips with, it is probably best to look for a tutorial or maybe a Python textbook.
Depending on how you make it work it is possible you can do everything without threads.

The main issue with most of the web tutorials for threading is they focus on doing the same task multiple times.
What you are likely to want is to have different tasks which are running in parallel instead.
It may be worth looking at the fairground model example another user made, it controls multiple rides each in a separate thread.
Original code: https://www.piborg.org/comment/475#comment-475
Fix to catch a CTRL+C event: https://www.piborg.org/comment/502#comment-502

We will not be at the Brighton Maker Fair unfortunately, we have a bit too much going on in September.
We do make a point of going to the Cambridge Raspberry Pi Jams since they are just up the road from us :)

I have just put the camera on him and changed crontab to run the code on boot, cant test the ball follow yet though cos I neglected to find a ball ... Doh!
However, I have noticed that you have used Threading in the code, so hope to have a play with it over the weekend, in conjunction with the Fairground code you linked to.

Thanks for the heads up on the Cambrigde Paspberry Pi Jam, I'll be there. Even though Mike thinks I'm crazy driving 120 miles for it. He's not wrong about me being crazy, but well worth the drive.
I'm looking forward to seeing you there.

How do you manage to paste code here with line numbers?
I SSH with Putty to make changes etc, using Nano. I'm guessing I need a different editor on my Pi?

piborg's picture

Wow, that is dedication!
Since we do not have a face to go with your name let us know who you are when you see us.
Hopefully we will be obvious enough from the mixture of robots and a near table heigh logo :)

To get Python code to show up in the forum with line numbers and highlighting you can surround it like this:

<pre class="brush:python">
Line 1
Line 2
...
Last line
</pre>

If you are starting from a line other than 1 you can do this instead:

<pre class="brush:python; first-line: 5;">
Line 5
Line 6
...
</pre>

You should be able to highlight lines in Putty when Nano is open using the mouse (left-click and drag).
This will copy the highlighted text, you should then be able to paste it into the forum text-box.

I will come and find you for sure, no doubt about that. Thats why I'm coming.

So you're gonna have a mixture of robots too eh ... Like I needed more reasons to make the trip.
Kid in a candy store springs to mind :-)

I've managed to mount a switch on him, without drilling holes.
https://www.piborg.org/node/1777
Hope it proves useful for others.

Thanks for the code posting help. Is there an editor for the RPi that shows line numbers?
And maybe one for Windows too?
At least Nano shows the different colours, but on Win it's just notepad, at least it does the job though.

piborg's picture

The switch is an awesome edition, clever thinking with using the posts to take the force.

I find having a good text editor makes coding a lot quicker, but there are so many to choose from.
Personally I use Vim / gVim as my main text editor on both Linux and Windows.
It is probably too scary / advanced for most users as it requires you to remember which keys do what (and there are a lot of them).
Even for advanced users it will not be to everyone's taste.

For Windows I have a fairly easy recommendation here: Notepad++.
It is still simple to use like Notepad or Nano, but it packs a ton of features in, including line numbers.

For Linux there are several editors in the graphical environment which fit nicely:

  • Geany - Offers some nice features such as listing the functions in a script
    If it is not already installed you can install it with sudo apt-get -y install geany
  • LeafPad - Similar to Notepad
    Very simple editor, but it come with line numbers and is installed by default on Raspbian.
  • gedit - The standard GNOME editor, similar level of functionality to Notepad++
    Install with sudo apt-get install gedit
  • Kate - a standard KDE editor, similar level of functionality to Notepad++
    Install with sudo apt-get install kate

The Linux terminal based editors are a little more tricky, so I will divide them into sections.
Installed by default on Raspbian:

  • Nano - Fairly friendly but fairly limited as well, does give syntax highlighting
  • Vi - Advanced editor too complicated for beginners, personally I would try Vim instead since it offers the same functionality plus a massive list of improvements

Intermediate editors:

  • JOE - Similar type of interface to Nano but with more powerful options
    Install using sudo apt-get install joe
    You can see line numbers if you use joe -linums filename
  • ne Nice Editor - Operates from a mixture of key presses or menus
    I cannot find a show line numbers option, but the status at the bottom shows current line and there is a "Goto line" option (Either CTRL+J or ESC → Search → Goto line).
    Install using sudo apt-get install ne

Advanced editors:

  • Vim - powerful editor that can be heavily customised, commands are based on multiple key presses
    Install with sudo apt-get install vim
    Alternatively use sudo apt-get install vim-gnome, this will also install gVim for the graphical environment
  • Emacs - powerful editor that can be heavily customised, commands are based on key combinations with CTRL, ALT, and ESC
    Install with sudo apt-get install emacs

Apologies for the late reply, work has been a bit manic.

Wow! That is a ton of options, thank you so much.
It will take me a while to find which I prefer, but it is fantastic to have so many options.
As always, you opinions are very much appreciated.

I've finally got my Pi Camera, so will be getting that incorporated as soon as I get the time.

I haven't given up on the LEDs, just had to put them on the back burner (I'm sure that isn't the best place to keep em lol) until I get a little more time.

Subscribe to Comments for &quot;PS3 Setup&quot;