ps3_demo

Andrew Dresner edited this page Mar 9, 2017 · 17 revisions

Overview of ps3_demo

This project allows the use of a Sony PS3 SixAxis Bluetooth gamepad to control basic functions of the robot.

Getting Started

Bluetooth & ps3_demo dependencies:

RaspberryPi/Raspbian: ps3_demo support is fully functional on the latest HR-OS1 raspbian image & Framework. You only need to install the Framework, follow the steps below to pair your controller, and launch the demo.

Edison/Yocto (LEGACY): We are currently using a Yocto build with Bluez4. BlueZ5 is supported as of the latest update to the Framework.

Pairing the SixAxis controller to your Robot

The SixAxis must first be paired to the robot prior to use. We use a simple program called sixpair that is available inside the project/ps3_demo/sixpair folder. There is a pre-compiled version for the RPi as well as the Edison variants (sixpair_rpi or sixpair_edison respectively).

  • (Edison only) turn on bluetooth: $ rfkill unblock bluetooth

  • Connect the controller to a USB port. (Note: For Edison, You will need to first disconnect the Arbotix-Pro from USB OTG port on Edison Mini Breakout Board).

  • Run sixpair:

$ sudo ./sixpair_rpi or $ ./sixpair_edison

  • sixpair will echo:

Current Bluetooth master: xx:xx:xx:xx:xx:xx

Setting master bd_addr to xx:xx:xx:xx:xx:xx

  • Disconnect the USB cable (Note: For Edison, reconnect Arbotix-Pro to USB OTG Port on Edison Mini Breakout Board).
  • Run the following commands to finalize pairing as a trusted device on Bluez5/RPI:

sudo bluetoothctl

discoverable on

agent on

  • You can now press the PS Button on the PS3 controller, you will see the PS3 device connectivity toggling in the bluetoothctl terminal output. You will need to make note of the Sixaxis' MAC Address, copy paste it for use in the next step.

Example:

[NEW] Device 38:C0:96:5C:C6:60 38-C0-96-5C-C6-60

[CHG] Device 38:C0:96:5C:C6:60 Connected: no

[DEL] Device 38:C0:96:5C:C6:60 38-C0-96-5C-C6-60

You will need to make a note of the your unique MAC address displayed, it is the sequence with ':' symbols.

In this example it is 38:C0:96:5C:C6:60.

With this we can attempt to make contact with the controller. We need to use the connect command with the MAC address shown, in our example:

  • Enter the bluetoothctl 'connect' command to initialize connection:

connect 38:C0:96:5C:C6:60

You are trying to get the Bluetooth to try a connection and get a UUID number. This may take several attempts, you can repeat the command using ↑ then ENTER. When it works you should see something like this:

'Attempting to connect to 38:C0:96:5C:C6:60`

[CHG] Device 38:C0:96:5C:C6:60 Modalias: usb:v054Cp0268d0100

[CHG] Device 38:C0:96:5C:C6:60 UUIDs:

00001124-0000-1000-8000-00805f9b34fb

00001200-0000-1000-8000-00805f9b34fb

Failed to connect: org.bluez.Error.Failed'

If the controller stops trying to connect press the PS button again before using the connect command again. Once we have seen the UUID values we can use the trust command to allow the controller to connect on its own.

  • Use the trust command with the MAC address from earlier, in our example:

trust 38:C0:96:5C:C6:60

If everything went well you should see something like:

[CHG] Device 38:C0:96:5C:C6:60 Trusted: yes

Changing 38:C0:96:5C:C6:60 trust succeeded

  • Finally exit the Bluetooth configuration tool and restart the Raspberry Pi.

quit

sudo reboot

Once you have logged back in press the PS button to test the connection. The LEDs should briefly flash, then just one LED should remain lit. You can then use the following command to list the connected joysticks:

ls /dev/input/js*

At least one should be shown, probably /dev/input/js0. You can test if the PS3 controller is working using the device name from the last command with jstest:

jstest /dev/input/js0

Compiling ps3_demo

The Makefile for ps3_demo is found here:

HROS1-Framework/Linux/project/ps3_demo

To compile ps3_demo:

make

ps3_demo walkthrough

Note: It is highly recommended that you have a 2nd person 'spot' the robot while you are getting accustomed to it, and especially during your initial power on and testing.

  1. Make sure the robot is in a sitting position, squatting on its haunches. This is the sitting position found in rme motion page 15. Arms should be free-moving and not caught on cables or surroundings.
  2. Make sure to disconnect the USB cable from the Sixaxis and Robot prior to trying to connect. Ensure your Arbotix-Pro subcontroller has been reconnected to your Edison/RPi if it was disconnected for pairing.
  3. To start the demo, execute the corresponding startup script. $ sudo ./demo This will move the robot into the sitting position and await for a connection with the Sixaxis controller before continuing.
  4. Press the PS button on the Sixaxis controller. All 4 LEDs should blink rapidly until connection is made to the robot. Upon connection the Sixaxis will assign a single LED to indicate channel. Press the PS button again to toggle standby mode, when in standby the robot will not respond to commands. DO NOT set down the controller before putting it into standby mode.
  5. From the robot's sitting position, press Triangle to move the robot into Walk Ready.
  6. Once in Walk Ready position, use the Left Joystick to test head movement. If the head is colliding with any of the frame or 3D shell components, you may need to adjust the CW/CCW Angle limits of the head servos using the dxl_monitor utility.
  7. Press R1 to initiate an Action Page Play. When this completes, the robot will be in the standing position. Press Triangle to go back to Walk Ready.
  8. From Walk Ready, press 'D-Pad Up' to turn the Walking Cycle On. The robot should be taking steps in place, moving forward very slightly. If the robot is not stably walking in place, press 'D-Pad Down' to stop the Walking Cycle immediately.
  9. With the Walk Cycle turned on, very slowly push the Right Joystick forward to walk the robot forward. Slowly bring the joystick back to center. Slowly push the Right Joystick Left to test turning. Return to center and press 'D-Pad Down' to stop the Walking Cycle.
  10. Press the 'X' button to sit the robot down.
  11. Run $ ./stop_ps3_demo to end the demo.

Sixaxis controller mapping

  • Cross - Sit
  • Triangle - Walk Ready Mode/Stand
  • PS Button - Toggle Standby
  • D-Pad Up - Turn Walking Cycle On
  • D-Pad Down - Turn Walking Cycle Off
  • Square, Circle, R1, R2, L1, L2 - Various motion pages
  • Start, Select, D-Pad Left, D-Pad Right - Unassigned
  • Left Joystick - Head movement (when in Walk Ready Mode)
  • Right Joystick - Walk forward/back/left/right

Control Tips & Tricks

  • If PS3 controller is not connecting, ensure it is charged and properly paired to your SBC. For troubleshooting/scripting, the basic premise of getting it to work is by killing the bluetooth daemon by issuing a $ pkill/killall bluetoothd command before starting the demo.
  • The Robot should always be in a sitting/squatting position before starting demo. Demo will start and move robot into sitting position.
  • Once in the sitting position, Triangle will bring the robot to the Walk Ready/Standing position. DO NOT attempt any action or walking cycle toggle while in the sitting position, as it will cause robot to abruptly stand and become unstable. This will be fixed in the next release.
  • Once in Walk Ready the Left Joystick will control the Head movement of the robot.
  • From Walk Ready position, any buttons bound to an action can be pressed. The robot will return to a Standing position at the end of any action.
  • Before turning Walk Cycle On, press Triangle to go from Sitting/Standing to Walk Ready. This prevents the robot from jumping directly into a walk.
  • Triangle should be pressed every time before turning Walk Cycle On. This can be used to reset the robot to it's Walk Ready position, which is used as 'home base' for actions and walking.
  • To walk the robot, press Triangle to go to Walk Ready, and then press 'D-Pad Up' to turn the Walking Cycle On. 'D-Pad Down' will turn Walking Cycle Off. When Walking Cycle is On, the Left Joystick will control the movement of the robot- forward, backward, turn left, and turn right.
  • Do not rapidly move either Joystick around, as this can cause the robot to become unstable. Smooth, minor movements and adjustments make for a smoother ride.

Misc.

Recompiling sixpair:

$ gcc -o sixpair sixpair.c -lusb

Legacy Edison Notes:

If you add the Edison community repos and run $ opkg update it may overwrite your Bluez4 install with Bluez5. If your Edison is running Bluez5, edit the start_edison script and replace the 'killall bluetoothd' command with 'hciconfig hci0 up' which toggles the stack in the same way.

References