![]() |
|
Construction Equipment If it digs, pushes, hauls dirt "off road" post it here. |
![]() |
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
![]()
On the Raspberry PI I run the below code. I keep it in a file /home/pi/dev/excavator/control.js
To run this program automatically when the Raspberry Pi gets power applied, just add this one line to /etc/rc.local (just before the "exit 0" line): Code:
cd /home/pi/dev/excavator/ && sudo /usr/local/bin/node control.js & The contents of /home/pi/dev/excavator/control.js: Code:
var fs = require('fs'); // Set a deadzone of +/-0 (no deadzone) (out of +/-32k) and a sensitivty of 100 to reduce signal noise in joystick axis var joystick = new (require('joystick'))(0, 0, 100); // State / config var speeds = { leftTrack: { current: 0, wanted: 0, accel: 1 }, rightTrack: { current: 0, wanted: 0, accel: 1 }, swing: { current: 0, wanted: 0, accel: 1 }, boom: { current: 0, wanted: 0, accel: 1 }, stick: { current: 0, wanted: 0, accel: 1 }, bucket: { current: 0, wanted: 0, accel: 1 } } // Upate current speeds based on wanted speed from joystick and accelleration limits var accelInterval = 20; setInterval(function () { for (var propName in speeds) { if (speeds.hasOwnProperty(propName)) { var speed = speeds[propName]; var accel = speed.accel * accelInterval / 1000; if (Math.abs(speed.current - speed.wanted) < accel) { speed.current = speed.wanted; } else { speed.current += speed.current > speed.wanted ? -accel : accel; } } } }, accelInterval); var leftTrackReverse = false; var rightTrackReverse = false; // Read the remote control joystick.on('axis', function (event) { // console.log(JSON.stringify(event)); // Typical event: { time: 1585158, value: 8783, number: 0, type: 'axis', id: 0 } var value = event.value / 32768; // Now in the -1 -> 0 -> 1 range value = value * Math.abs(value); // Exponential switch (event.number) { case 0: speeds.swing.wanted = -value; break; // Left stick horizontal / swing case 1: speeds.stick.wanted = -value; break; // Left stick vertical / stick case 3: speeds.bucket.wanted = -value; break; // Rigth stick horizontal / bucket case 4: speeds.boom.wanted = -value; break; // Rigth stick verical / boom case 2: speeds.leftTrack.wanted = (leftTrackReverse ? -1 : 1) * ((value + 1) / 2); break; case 5: speeds.rightTrack.wanted = (rightTrackReverse ? -1 : 1) * ((value + 1) / 2); break; } }); joystick.on('button', function (event) { // console.log(JSON.stringify(event)); // Typical event: { time: 1607722, value: 0, number: 0, type: 'button', id: 0 } if (event.number === 4) { // Left top shoulder leftTrackReverse = event.value !== 0; } if (event.number === 5) { // Rigt top shoulder rightTrackReverse = event.value !== 0; } }); // The motor controllers var SerialPort = require("serialport").SerialPort; function startMotorControllerOn(devicePath) { var serialPort = new SerialPort(devicePath, { baudrate: 9600 }); serialPort.on('open', function () { serialPort.on('data', function (data) { var deviceId = data[0]; console.log('Got device id: ' + deviceId + ' from ' + devicePath); clearInterval(idInterval); setInterval(function () { var motor0Speed = 0; var motor1Speed = 0; switch (deviceId) { case 10: motor0Speed = speeds.leftTrack.current; motor1Speed = speeds.rightTrack.current; break; case 11: motor0Speed = speeds.swing.current; motor1Speed = speeds.boom.current; break; case 12: motor0Speed = speeds.stick.current; motor1Speed = speeds.bucket.current; break; } var cmd = motor0Speed >= 0 ? 0x88 : 0x8A; serialPort.write([cmd, Math.abs(motor0Speed) * 127]); cmd = motor1Speed >= 0 ? 0x8C : 0x8E; serialPort.write([cmd, Math.abs(motor1Speed) * 127]); // console.log(JSON.stringify({ d: deviceId, a: motor0Speed, b: motor1Speed})); }, 50); }); var idInterval = setInterval(function () { console.log('Sending request for device id... to ' + devicePath); serialPort.write([0x83, 0]); console.log('Sent request for device id... to ' + devicePath); }, 1000); }); } startMotorControllerOn('/dev/ttyUSB0'); startMotorControllerOn('/dev/ttyUSB1'); startMotorControllerOn('/dev/ttyUSB2'); |
#2
|
|||
|
|||
![]()
The first test drive of the full working skeleton!
![]() https://youtu.be/ueaT-cYe8B4 The lead ballast is not mounted in this video. And as as you can see in the video, it really needs to be added. Too little weight in the back. :-) I'm quite happy with the handling. It is very precise and very strong. Also, it's dead quiet except for the swing motor. I don't know why that motor is making so much noise. I have ordered another one just to make sure it isn't just that one particular motor. |
#3
|
||||
|
||||
![]()
Very nice job! It's nice to see something different although the control boards are way over my head.lol
On a different note. How did you post your video(embed) like that on this site? I didn't think we could do that here. I'm glad we can! Keep up the great work! Reg |
#4
|
|||
|
|||
![]()
Thanks, Kevin, Jim and Reg! :-)
Quote:
How I did it: 1. Upload the video to YouTube 2. Copy the embed code from YouTube 3. Paste the embed code into "TryIt Editor" - http://www.w3schools.com/html/tryit....=tryhtml_basic 4. Take a screenshot 5. Crop the screenshot to only include the image of the embedded player 6. Upload the player screenshot to my image server 7. Add the image to the forum post 8. Add a link to the video on YouTube around the image (e.g. [ url= ..] [ img=.. [ /img ] [ /url ] ) so that the image becomes clickable. Quite a few steps. Not sure if I'm going to do it again. :-) Best regards, Stein :-) |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|