项目作者: cncjs

项目描述 :
用于CNCjs的Dual Shock / PS3蓝牙遥控器
高级语言: JavaScript
项目地址: git://github.com/cncjs/cncjs-pendant-ps3.git
创建时间: 2017-01-30T18:38:13Z
项目社区:https://github.com/cncjs/cncjs-pendant-ps3

开源协议:MIT License

下载


cncjs-pendant-ps3

Dual Shock / PS3 Bluetooth Remote Pendant for CNCjs


NOTE: A more up-to-date implimentation can be found at balthisar/cncjs-pendant-gamepad.


Use Playstation 3 Controller wirelessly over bluetooth to control CNC from the host device (raspberry pi). PS3 CNC Control Button Map

Remote Pendant (Playstation 3 Dualshock Controller / SIXAXIS Controller)

Using a wireless game controller (like a PS3 controller) seems to be one of the lowest cost & simplest solution method. See related issue #103

Playstation Controller Setup ( general guide to connect hardware & setup )

Here is what I have figured out so far for PS3 on Raspberry PI 3 w/ integrated bluetooth.
The bellow just shows how to get PS3 controller connected.

Bluetooth Configuration

Install

  1. # Install & Enable Bluetooth Tools
  2. sudo apt-get install -y bluetooth libbluetooth3 libusb-dev
  3. sudo systemctl enable bluetooth.service
  4. # Add pi user to bluetooth group
  5. sudo usermod -G bluetooth -a pi

Pairing Tools

  1. # Get and build the command line pairing tool (sixpair)
  2. wget http://www.pabr.org/sixlinux/sixpair.c
  3. gcc -o sixpair sixpair.c -lusb
  4. ### Connect PS3 over USB
  5. # Get PS3 DS
  6. sudo ./sixpair

Parting DualShock 3 Controller

  1. ### Disonnect DualShock 3 over USB
  2. # Start bluetoothctl:
  3. bluetoothctl
  4. # Enable the agent and set it as default:
  5. agent on
  6. default-agent
  7. # Power on the Bluetooth controller, and set it as discoverable and pairable:
  8. power on
  9. discoverable on
  10. pairable on
  11. ### Connect DualShock 3 over USB, and press the PlayStation button.
  12. # Discover the DualShock 3 MAC address:
  13. devices
  14. ### Disonnect DualShock 3 over USB
  15. #Allow the service authorization request:
  16. #[agent]Authorize service service_uuid (yes/no): yes
  17. #Trust the DualShock 3:
  18. #trust device_mac_address # Replace "MAC" with MAC of "Device 64:D4:BD:B3:9E:66 PLAYSTATION(R)3 Controller"
  19. trust 64:D4:BD:B3:9E:66
  20. # The DualShock 3 is now paired:
  21. quit
  22. # Turn the DualShock 3 off when it's no longer in use by pressing and holding the PlayStation button for 10 seconds.
  23. # Press the PlayStation button to use the DualShock 3 again.

Test Controller Connectivity

  1. ### PS3 Controller: press the PS button, the lights on the front of the controller should flash for a couple of seconds then stop, leaving a single light on. If you now look again at the contents of /dev/input you should see a new device, probably called something like ‘js0’:
  2. # List Devices
  3. ls /dev/input

Get Battery Level

cat "/sys/class/power_supply/sony_controller_battery_64:d4:bd:b3:9e:66/capacity"

Joystick Application

  1. # Install
  2. sudo apt-get -y install joystick
  3. # Usage / Test
  4. jstest /dev/input/js0

Install NodeJS Libraries

Node.js DS3 Controller Setup

  1. # Install Tools
  2. sudo apt-get install -y libudev-dev libusb-1.0-0 libusb-1.0-0-dev build-essential git
  3. sudo apt-get install -y gcc-4.8 g++-4.8 && export CXX=g++-4.8
  4. #npm install node-gyp node-pre-gyp
  5. # Install node-hid with hidraw support
  6. #npm install node-hid --driver=hidraw --build-from-source --unsafe-perm
  7. # Install Pendant Package
  8. sudo npm install -g cncjs-pendant-ps3 --unsafe-perm # Install Globally
  9. ## If NOT installed globally, Install node-hid with hidraw support (https://github.com/rdepena/node-dualshock-controller)

Create udev Rules

  1. # Run as Root
  2. sudo su
  3. # You will need to create a udev rule to be able to access the hid stream as a non root user.
  4. sudo touch /etc/udev/rules.d/61-dualshock.rules
  5. sudo cat <<EOT >> /etc/udev/rules.d/61-dualshock.rules
  6. SUBSYSTEM=="input", GROUP="input", MODE="0666"
  7. SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0268", MODE:="666", GROUP="plugdev"
  8. KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"
  9. SUBSYSTEM=="input", GROUP="input", MODE="0666"
  10. SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE:="666", GROUP="plugdev"
  11. KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"
  12. EOT
  13. # Reload the rules, then disconnect/connect the controller.
  14. sudo udevadm control --reload-rules
  15. exit

QUICK FIX for node-hid hidraw… PLEASE HELP IF YOU KNOW FIX

  1. # I am having issues with node-hid --driver=hidraw not seeming to work... quickest fix is to reinstall, node-hid --driver=hidraw
  2. # Reinstall (node-hid --driver=hidraw) on cncjs-pendant-ps3
  3. cd /usr/lib/node_modules/cncjs-pendant-ps3/
  4. sudo npm install node-hid --driver=hidraw --build-from-source --unsafe-perm

I recommend rebooting now.
After reboot you can test pendant by running cncjs-pendant-ps3 -p "/dev/ttyUSB0".


Auto Start

Install Production Process Manager [PM2]

  1. # Install Production Process Manager [PM2]
  2. npm install pm2 -g
  3. # Setup PM2 Startup Script
  4. pm2 startup debian
  5. #[PM2] You have to run this command as root. Execute the following command:
  6. sudo su -c "env PATH=$PATH:/home/pi/.nvm/versions/node/v4.5.0/bin pm2 startup debian -u pi --hp /home/pi"
  7. # Start Dual Shock / PS3 Bluetooth Remote Pendant for CNCjs (conected to serail device @ /dev/ttyUSB0) with PM2
  8. pm2 start $(which cncjs-pendant-ps3) -- -p "/dev/ttyUSB0"
  9. # Set current running apps to startup
  10. pm2 save
  11. # Get list of PM2 processes
  12. pm2 list