RC Truck and Construction  

Go Back   RC Truck and Construction > RC Truck's Ag and Industrial Equipment and Buildings > Construction Equipment

Construction Equipment If it digs, pushes, hauls dirt "off road" post it here.


Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2015, 05:57 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

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');
Reply With Quote
  #2  
Old 12-14-2015, 06:22 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

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.
Reply With Quote
  #3  
Old 12-15-2015, 10:52 AM
RCP57's Avatar
RCP57 RCP57 is offline
Big Dawg On The Bone
 
Join Date: Mar 2011
Location: Vancouver Island
Posts: 3,677
RCP57 is on a distinguished road
Default Re: 90 ton 1/14 metal excavator scratch build w/embedded PC

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
Reply With Quote
  #4  
Old 12-15-2015, 03:38 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

Thanks, Kevin, Jim and Reg! :-)


Quote:
Originally Posted by RCP57 View Post
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!
I don't think this site support video embedding. What I did above is just to add a screenshot of the embedding in a link to YouTube. I did that because I was afraid that the video would drown in all the (boring) programming code I was pasting in the previous posts. and so I wanted it to stand out and look like a video.

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 :-)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:57 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.