View Single Post
  #51  
Old 12-05-2015, 03:29 PM
SteinHDan SteinHDan is offline
Green Horn
 
Join Date: Sep 2015
Location: Oslo, Norway
Posts: 188
SteinHDan is on a distinguished road
Default Re: 90 ton 1/14 metal excavator scratch build w/embedded PC

Any USB joystick or gamepad can be used for controls.

I'm using a very accurate gamepad from LogiTech. It also has a tiny receiver, which is good when the space is limited:
- Logitech F710

together with the npm joystick module:

Reading the gamepad is done like this:

Code:
var joystick = new (require('joystick'))(0, 3500, 350);

joystick.on('axis', function(event) {
    // Typical Event: { time: 22283520, value: 32636, number: 3, type: 'axis', id: 0 }
    var value = event.value / 32768; // Normalize to the range -1.0 - 0 - 1.0
    if (event.number === 3) { // 3 is left/right on the right pad
        steeringPos = value;
    }
});
Reply With Quote