Code Monkey home page Code Monkey logo

cncjs-pendant-ps3's Introduction

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

# Install & Enable Bluetooth Tools
sudo apt-get install -y bluetooth libbluetooth3 libusb-dev
sudo systemctl enable bluetooth.service

# Add pi user to bluetooth group
sudo usermod -G bluetooth -a pi

Pairing Tools

# Get and build the command line pairing tool (sixpair)
wget http://www.pabr.org/sixlinux/sixpair.c
gcc -o sixpair sixpair.c -lusb

### Connect PS3 over USB
# Get PS3 DS 
sudo ./sixpair
### Disonnect DualShock 3 over USB

# Start bluetoothctl:
bluetoothctl

# Enable the agent and set it as default:
agent on
default-agent

# Power on the Bluetooth controller, and set it as discoverable and pairable:
power on
discoverable on
pairable on

### Connect DualShock 3 over USB, and press the PlayStation button.

# Discover the DualShock 3 MAC address:
devices

### Disonnect DualShock 3 over USB

#Allow the service authorization request:
#[agent]Authorize service service_uuid (yes/no): yes

#Trust the DualShock 3:
#trust device_mac_address # Replace "MAC" with MAC of "Device 64:D4:BD:B3:9E:66 PLAYSTATION(R)3 Controller"
trust 64:D4:BD:B3:9E:66 

# The DualShock 3 is now paired:
quit

# Turn the DualShock 3 off when it's no longer in use by pressing and holding the PlayStation button for 10 seconds.
# Press the PlayStation button to use the DualShock 3 again.

Test Controller Connectivity

### 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’:

# List Devices
ls /dev/input

Get Battery Level

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

Joystick Application

# Install
sudo apt-get -y install joystick

# Usage / Test
jstest /dev/input/js0

Install NodeJS Libraries

Node.js DS3 Controller Setup

# Install Tools
sudo apt-get install -y libudev-dev libusb-1.0-0 libusb-1.0-0-dev build-essential git
sudo apt-get install -y gcc-4.8 g++-4.8 && export CXX=g++-4.8
#npm install node-gyp node-pre-gyp

# Install node-hid with hidraw support
#npm install node-hid --driver=hidraw --build-from-source --unsafe-perm

# Install Pendant Package
sudo npm install -g cncjs-pendant-ps3 --unsafe-perm  # Install Globally

## If NOT installed globally, Install node-hid with hidraw support (https://github.com/rdepena/node-dualshock-controller)
# Run as Root
sudo su

# You will need to create a udev rule to be able to access the hid stream as a non root user.
sudo touch /etc/udev/rules.d/61-dualshock.rules
sudo cat <<EOT >> /etc/udev/rules.d/61-dualshock.rules
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0268", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"

SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"
EOT

# Reload the rules, then disconnect/connect the controller.
sudo udevadm control --reload-rules

exit

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

# I am having issues with node-hid --driver=hidraw not seeming to work... quickest fix is to reinstall, node-hid --driver=hidraw 

# Reinstall (node-hid --driver=hidraw) on cncjs-pendant-ps3
cd /usr/lib/node_modules/cncjs-pendant-ps3/
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]
npm install pm2 -g

# Setup PM2 Startup Script
pm2 startup debian
  #[PM2] You have to run this command as root. Execute the following command:
  sudo su -c "env PATH=$PATH:/home/pi/.nvm/versions/node/v4.5.0/bin pm2 startup debian -u pi --hp /home/pi"

# Start Dual Shock / PS3 Bluetooth Remote Pendant for CNCjs (conected to serail device @ /dev/ttyUSB0) with PM2
pm2 start $(which cncjs-pendant-ps3) -- -p "/dev/ttyUSB0"

# Set current running apps to startup
pm2 save

# Get list of PM2 processes
pm2 list

cncjs-pendant-ps3's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cncjs-pendant-ps3's Issues

Feature Request: Widget to manage connection

I am making an image that will run cnc.js (based off of the octopi image). I can easily do a lot of configuring ahead of time (like build the sixaxis software, and install bluetooth tools) but the user will not have much Linux experience. It would be great if there was a widget that could let me pair a controller, and even better would be to also allow any /dev/js* controller. The code would probably work fine with other controllers too, although the button order might be different. Things like a wired xbox style controller can be had for about $20 (https://www.amazon.com/controller-Rottay-Controller-Shoulders-Microsoft/dp/B076WYKP4D). They show up in Linux the same way the ps3 one does, after connection (jstest works on them, for example).

I can help with the Linux stuff, and I can look at the different bluetooth utilities to try and figure out how to get them to be trusted, but I looked at the widget things, and I'm at a loss. I don't know how I would call system calls from the widget buttons, and how I would make a connection to the widget to update status, and everything else. I think I can figure out this .js script fine, and probably figure out where to connect to a different type of controller.

Wrong token?

I'm having trouble getting my controller to move the machine. I was able to install cncjs-pendant-ps3 following your instructions, and I went into the code and uncommented some of the console.log() lines to see what it was doing. I can run the program just fine over ssh and the pendant appears to connect, but when I manipulate the PS3 controller the machine never reacts.

I noticed that the token shown by cncjs-pendant-ps3 is not the same as the one listed by my cncjs instance. It looks like the text before the first period is identical, but after that they are not the same.

SSH Output:

pi@v1pi:~ $ cncjs-pendant-ps3 -p /dev/input/js0
Waiting for Pendant to connect... please press the PS button on the DS3 controller.
Pendant Connected
connection:change:Not Charging
battery:change:Charging
connection:change:Rumbling
Connected to ws://localhost:8000?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IiIsIm5hbWUiOiJjbmNqcy1wZW5kYW50IiwiaWF0IjoxNTgzMDgzOTkwLCJleHAiOjE1ODU2NzU5OTB9.gcSId2tNqT9-qHNmtgLI54Y-RRPYyPPo7vbcWLGtApM
DPad MOVE: 1.5 : 0 : 0
DPad MOVE: 10 : 0 : 0
DPad MOVE: 0.5 : 0 : 0
DPad MOVE: 10.5 : 0 : 0
DPad MOVE: 0.5 : 0 : 0
DPad MOVE: 10.5 : 0 : 0

CNCJS Workspace JSON info:

{
  "version": "1.9.20",
  "state": {
    "session": {
      "name": "",
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IiIsIm5hbWUiOiIiLCJpYXQiOjE1ODMwODM3NTEsImV4cCI6MTU4NTY3NTc1MX0.kTPiLnss9hQ42cfooCwPJCPvJeaXh6HgTYJmfFbnv5g",
      "enabled": false
    },

I'm getting a bunch of warnings followed by errors

When I run the command "sudo npm install -g cncjs-pendant-ps3 --unsafe-perm # Install Globally" I get a bunch of messages about "npm WARN deprecated. . ." eventually I get a compilation terminated and then a bunch of "gyp ERR!" Is this feature still alive or is it too outdated to work with a PS4 controller? The instructions for connecting the controller didn't work for me but I was able to get it connected and test it using a different article https://salamwaddah.com/blog/connecting-ps4-controller-to-raspberry-pi-via-bluetooth
image

Have to run as sudo, controller doesn't move the carriage

Even though I did the udevadm step, running the pendant doesn't recognize me pushing the PS3 button unless I run it as sudo.

After that, it responds with this then nothing else happens and I can't get it to jog the carriage.
Am I missing something???

pi@lowrider:~ $ cncjs-pendant-ps3 -p "/dev/ttyUSB0"
Waiting for Pendant to connect... please press the PS button on the DS3 controller.
^Cpi@lowrider:~ $ sudo cncjs-pendant-ps3 -p "/dev/ttyUSB0"
Waiting for Pendant to connect... please press the PS button on the DS3 controller.
Pendant Connected
connection:change:Not Charging
battery:change:80%
connection:change:Rumbling
Connected to ws://localhost:8000?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IiIsIm5hbWUiOiJjbmNqcy1wZW5kYW50IiwiaWF0IjoxNTY4MDY0NDUxLCJleHAiOjE1NzA2NTY0NTF9.mdpCi6ob4xiHSqRXDJjMYeBnZVp2n1I8p4Ck_l164-A

Publish Package to NPM

This is just a friendly reminder that you can publish your package to npm once it's ready for production use. I just created a package.json file, and added several command-line options as well:

$ cncjs-pendant-ps3 --help

  Usage: cncjs-pendant-ps3 -p <port> [options]

  Options:

    -h, --help                  output usage information
    -V, --version               output the version number
    -l, --list                  list available ports then exit
    -p, --port <port>           path or name of serial port (default: /dev/ttyUSB0)
    -b, --baudrate <baudrate>   baud rate (default: 115200)
    --socket-address <address>  socket address or hostname (default: localhost)
    --socket-port <port>        socket port (default: 8000)
    --controller-type <type>    controller type: Grbl|Smoothie|TinyG (default: Grbl)

$ cncjs-pendant-ps3 --list
/dev/cu.Bluetooth-Incoming-Port
/dev/cu.iPhoneLAVA-WirelessiAP
/dev/cu.usbmodemFA131

setExtras timeout error

I'm trying to use a clone dualshock 3 controller (Shanwan controller) in my fresh installed rapsbian / rpi 3.

First, I have problems with pairing/using the controller with BT, so, I'm finally using a patched bluez version to get it work (see https://raspberryblog.de/?p=1870).

With this issue solved, I have problems with cncjs-pendant-ps3, exactly in the setExtras invocation, some seconds after starting, I got this error (it sets the leds according to battery level right):

root@raspberrypi:/usr/lib/node_modules/cncjs-pendant-ps3# cncjs-pendant-ps3 -p /dev/ttyUSB0
[ { vendorId: 1356,
productId: 616,
path: '/dev/hidraw0',
serialNumber: '03:c7:98:6e:63:25',
manufacturer: '',
product: 'PLAYSTATION(R)3 Controller',
release: 0,
interface: -1 } ]
Waiting for Pendant to connect... please press the PS button on the DS3 controller.
Pendant Connected
connection:change:Not Charging
battery:change:80%
connection:change:Rumbling
Connected to ws://localhost:8000?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IiIsIm5hbWUiOiJjbmNqcy1wZW5kYW50IiwiaWF0IjoxNTI0OTI2NTUzLCJleHAiOjE1Mjc1MTg1NTN9.7yFZBvugUp3pnTBHP1bC5rcuDhRjev0_tNg1zF7JGrg
Connected to port "/dev/ttyUSB0" (Baud rate: 115200)
/usr/lib/node_modules/cncjs-pendant-ps3/node_modules/dualshock-controller/src/controller.js:131
device.write(buff);
^

Error: Cannot write to HID device
at Controller.setExtras (/usr/lib/node_modules/cncjs-pendant-ps3/node_modules/dualshock-controller/src/controller.js:131:16)
at Timeout.updateControllerExtras [as _onTimeout] (/usr/lib/node_modules/cncjs-pendant-ps3/index.js:803:16)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)

Then, if I just comment the setExtras invocation, I can get the pendant working great, but no battery leds or rumble feedback:

            // Send Extras Updates
            setInterval(updateControllerExtras, 500);
            function updateControllerExtras() {
            ///             controller.setExtras({
            ///             rumbleLeft:  ps3_rumble_left,   // 0-1 (Rumble left on/off)
            ///             rumbleRight: ps3_rumble_right,   // 0-255 (Rumble right intensity)
            ///             led: ps3_led // 2 | 4 | 8 | 16 (Leds 1-4 on/off, bitmasked)
            ///     });

                    //console.log("ps3_rumble_left: " + ps3_rumble_left);
                    //console.log("ps3_rumble_right: " + ps3_rumble_right);
            }

If I make a simple nodejs code calling the setExtras function, I can control the leds and rumbling without problems.

Any idea?

Setup

What is the setup -- any PS3 controller or official one or any knock off, etc?

I presume you need a BT dongle on the PI... is there not different versions of BT?

Is it 4.0 ? I guess if I have the latest Pi Bluetooth is built in.

Just trying to understand what hardware is need prior to attempting to use this awesome looking feature.

Error on install cncjs-pendant-ps3

Hi,

I'm desperatly trying to install and make work cncjs-pendant-ps3 wich made me dream about driving my cnc with a PS3 controller.
I followed all the steps with sudo, if not i got some permissions err
everything seems to be good until :

sudo npm install -g cncjs-pendant-ps3 --unsafe-perm

the return is :

ERR! code 1
npm ERR! path /usr/local/lib/node_modules/cncjs-pendant-ps3/node_modules/node-hid
npm ERR! command failed
npm ERR! command sh -c prebuild-install || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | arm
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack 
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (child_process.js:308:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
npm ERR! gyp ERR! stack     at maybeClose (internal/child_process.js:1022:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
npm ERR! gyp ERR! System Linux 5.15.32-v7l+
npm ERR! gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/cncjs-pendant-ps3/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/cncjs-pendant-ps3/node_modules/node-hid
npm ERR! gyp ERR! node -v v12.22.5
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-03T14_55_36_707Z-debug.log

May I get some help for that ?

Thanks for reading

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.