Coder Social home page Coder Social logo

cncjs-pendant-ps3's Introduction

CNCjs Backers on Open Collective Sponsors on Open Collective Travis CI Build Status AppVeyor Build status Coverage Status

NPM cncjs

CNCjs is a full-featured web-based interface for CNC controllers running Grbl, Marlin, Smoothieware, or TinyG.

For a more complete introduction, see the Introduction section of the wiki page.

cncjs

Features

Custom Widgets

Pendants

Boilerplate Code

Existing Pendants

Tablet UI

Browser Support

Chrome
Chrome
Edge
Edge
Firefox
Firefox
IE
IE
Opera
Opera
Safari
Safari
Yes Yes Yes Not supported Yes Yes

Supported Node.js Versions

Version Supported Level
<= 10 Not supported
12 Supported
>= 14 Recommended

Getting Started

Node.js Installation

Node.js 14 or higher is recommended. You can install Node Version Manager to manage multiple Node.js versions. If you have git installed, just clone the nvm repo, and check out the latest version:

git clone https://github.com/creationix/nvm.git ~/.nvm
cd ~/.nvm
git checkout `git describe --abbrev=0 --tags`
cd ..
. ~/.nvm/nvm.sh

Add these lines to your ~/.bash_profile, ~/.bashrc, or ~/.profile file to have it automatically sourced upon login:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

Once installed, you can select Node.js versions with:

nvm install 14
nvm use 14

It's also recommended that you upgrade npm to the latest version. To upgrade, run:

npm install npm@latest -g

Installation

Install cncjs as a non-root user, or the serialport module may not install correctly on some platforms like Raspberry Pi.

npm install -g cncjs

If you're going to use sudo or root to install cncjs, you need to specify the --unsafe-perm option to run npm as the root account.

sudo npm install --unsafe-perm -g cncjs

Check out https://github.com/cncjs/cncjs/wiki/Installation for other installation methods.

Upgrade

Run npm install -g cncjs@latest to install the latest version. To determine the version, use cncjs -V.

Usage

Run cncjs to start the server, and visit http://yourhostname:8000/ to view the web interface. Pass --help to cncjs for more options.

pi@rpi3$ cncjs -h

  Usage: cncjs [options]


  Options:

    -V, --version                       output the version number
    -p, --port <port>                   Set listen port (default: 8000)
    -H, --host <host>                   Set listen address or hostname (default: 0.0.0.0)
    -b, --backlog <backlog>             Set listen backlog (default: 511)
    -c, --config <filename>             Set config file (default: ~/.cncrc)
    -v, --verbose                       Increase the verbosity level (-v, -vv, -vvv)
    -m, --mount <route-path>:<target>   Add a mount point for serving static files
    -w, --watch-directory <path>        Watch a directory for changes
    --access-token-lifetime <lifetime>  Access token lifetime in seconds or a time span string (default: 30d)
    --allow-remote-access               Allow remote access to the server (default: false)
    --controller <type>                 Specify CNC controller: Grbl|Marlin|Smoothie|TinyG|g2core (default: '')
    -h, --help                          output usage information

  Examples:

    $ cncjs -vv
    $ cncjs --mount /pendant:/home/pi/tinyweb
    $ cncjs --mount /widget:~+/widget --mount /pendant:~/pendant
    $ cncjs --mount /widget:https://cncjs.github.io/cncjs-widget-boilerplate/v1/
    $ cncjs --watch-directory /home/pi/watch
    $ cncjs --access-token-lifetime 60d  # e.g. 3600, 30m, 12h, 30d
    $ cncjs --allow-remote-access
    $ cncjs --controller Grbl

Instead of passing command line options for --watch-directory, --access-token-lifetime, --allow-remote-access, and --controller, you can create a ~/.cncrc file that contains the following configuration in JSON format:

{
    "mountPoints": [
        {
            "route": "/pendant",
            "target": "/home/pi/tinyweb"
        },
        {
            "route": "/widget",
            "target": "https://cncjs.github.io/cncjs-widget-boilerplate/v1/"
        }
    ],
    "watchDirectory": "/path/to/dir",
    "accessTokenLifetime": "30d",
    "allowRemoteAccess": false,
    "controller": ""
}

To troubleshoot issues, run:

cncjs -vvv

Configuration File

The configuration file .cncrc contains settings that are equivalent to the cncjs command-line options. The configuration file is stored in user's home directory. To find out the actual location of the home directory, do the following:

  • Linux/Mac

    echo $HOME
  • Windows

    echo %USERPROFILE%

Check out an example configuration file here.

File Format

See #242 (comment) for a detailed explanation.

{
  "ports": [
     {
       "path": "/dev/ttyAMA0",
       "manufacturer": ""
     }
  ],
  "baudrates": [115200, 250000],
  "mountPoints": [
    {
      "route": "/widget",
      "target": "https://cncjs.github.io/cncjs-widget-boilerplate/v1/"
    }
  ],
  "watchDirectory": "/path/to/dir",
  "accessTokenLifetime": "30d",
  "allowRemoteAccess": false,
  "controller": "",
  "state": {
    "checkForUpdates": true,
    "controller": {
      "exception": {
        "ignoreErrors": false
      }
    }
  },
  "commands": [
    {
      "title": "Update (root user)",
      "commands": "sudo npm install -g cncjs@latest --unsafe-perm; pkill -f cncjs"
    },
    {
      "title": "Update (non-root user)",
      "commands": "npm install -g cncjs@latest; pkill -f cncjs"
    },
    {
      "title": "Reboot",
      "commands": "sudo /sbin/reboot"
    },
    {
      "title": "Shutdown",
      "commands": "sudo /sbin/shutdown"
    }
  ],
  "events": [],
  "macros": [],
  "users": []
}

Documentation

https://cnc.js.org/docs/

Examples

There are several *.gcode files in the examples directory. You can use the GCode widget to load a GCode file and make a trial run.

If you don't have a CAM software, try using jscut to create G-Code from *.svg. It's a simple CAM package that runs in the browser.

Check out a live demo at http://jscut.org/jscut.html.

Contributions

Use GitHub issues for requests.

Pull requests welcome! Learn how to contribute.

Localization

You can help translate resource files in both of app and server directories from English to other languages. Check out Localization guide to learn how to get started. If you are not familiar with GitHub development, you can open an issue or send your translations to [email protected].

Locale Language Status Contributors
cs Čeština (Czech) Miroslav Zuzelka
de Deutsch (German) Thorsten Godau, Max B.
es Español (Spanish) Juan Biondi
fr Français (French) Simon Maillard, CorentinBrulé
hu Magyar (Hungarian) Sipos Péter
it Italiano (Italian) vince87
ja 日本語 (Japanese) Naoki Okamoto
nl Nederlands (Netherlands) dutchpatriot
pt-br Português (Brasil) cmsteinBR
ru Ру́сский (Russian) Denis Yusupov
uk Український (Ukraine) khvalera
tr Türkçe (Turkish) Ali GÜNDOĞDU
zh-cn 简体中文 (Simplified Chinese) Mandy Chien, Terry Lee
zh-tw 繁體中文 (Traditional Chinese) Cheton Wu

Donate

If you would like to support this project, you can make a donation using PayPal. Thank you!

Donate

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

Licensed under the MIT License.

cncjs-pendant-ps3's People

Contributors

austinsaintaubin avatar cheton avatar

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

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

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

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

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

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.

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
    },

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.

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?

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.