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, 06:30 AM
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

Wiring the electronics:

I ended up buying the motor controllers and the Arduinos on Ebay. The Arduinos ar Nhduinos, a Chinese clone that is a bit cheaper than the original Arduino.


Soldering the Monster motor shield:

I think the motor shield usually ships without the through-hole components soldered. The ones I bought also came without the screw terminals, so I had to use some that I had laying around. I used a quite big one on the battery connector, so that I can add a standard XT60 connector and leads to it:






I cut away the ISP header on the Arduino as it was in the way of the bigger screw terminal and I'm not going to use it anyway:




The monster motor shield then snaps onto the Arduino.
Adding a standard XT60 connector:






This is how the motor controller connects to the Raspberry Pi (USB) and a gear motor:




Adding a 3S LiPo battery and a 5V BEC. The standard servo connector on the BEC incidentally fits exactly onto the 5V header input on the Raspberry PI:




Finally, adding the wireless gamepad and receiver.

The setup isn't that different from a normal RC setup. In this picture, each of the components have the same role as their normal RC counterpart:

- Remote control: Wireless gamepad
- Receiver: Raspberry Pi
- ESC: Monster motor shield
- Battery: Battery
- BEC: BEC
- Motor: Motor




To control six gear motors, I use three motor drivers. To control them all at the same time, I use a self-powered USB hub:




And I made this crude power switch with three outputs:

Reply With Quote
  #2  
Old 12-14-2015, 07:12 AM
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

To program the motor drivers so that they are Pololu Qik compatible (for the commands "GetDeviceId", "SetMotor1Speed" and "SetMotor2Speed"), follow these steps:
1. Connect the USB cable to a PC
2. Download the Arduino programmer: https://www.arduino.cc/en/Main/Software
3. Copy and paste the code below into the programming tool
4. Set the device ID on the second line (any number from 0 to 255, used to identify the controller later) I'm using device IDs 10, 11 and 12 for this build.
5. Click the "Upload" button

Done!

I also added a serial command timeout, which means that the motor driver will stop the motor if it has not received a motor command for one second. Usually the Raspberry Pi will send a motor command 50 times per second, but in the case it loses power or is disconnected for some reason, the motor will stop.

I've not added current sensing or limiting yet.

Code:
/*  Based on the MonsterMoto Shield Example Sketch by: Jim Lindblom */
int deviceId = 10;

#define BRAKEVCC 0
#define CW   1
#define CCW  2
#define BRAKEGND 3
#define CS_THRESHOLD 100

// VNH2SP30 pin definitions
int inApin[2] = {7, 4};  // INA: Clockwise input
int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {5, 6}; // PWM input
int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)

// Serial state
int inByte = 0;
int command = 0;
unsigned long lastCommandTime = 0;
unsigned long timeoutMillis = 1000;

void setup() {
  setPwmFrequency(5, 8);
  setPwmFrequency(6, 8);
  
  // Initialize digital pins as outputs
  for (int i=0; i<2; i++)
  {
    pinMode(inApin[i], OUTPUT);
    pinMode(inBpin[i], OUTPUT);
    pinMode(pwmpin[i], OUTPUT);
  }
  // Initialize motors braked
  motorGo(0, BRAKEGND, 0);
  motorGo(1, BRAKEGND, 0);
  
  // start serial port at 9600 bps:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() {
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    if (inByte > 127)
      command = inByte;
    else if (command != 0) {
      int speed = inByte * 2; // From 0-127 range to 0-254 range
      int motor = -1;
      int direction = CW;
      switch(command) {
        case 0x88: motor = 0; direction = CW; break;
        case 0x8A: motor = 0; direction = CCW; break;
        case 0x8C: motor = 1; direction = CW; break;
        case 0x8E: motor = 1; direction = CCW; break;
        case 0x83: motor = -1; Serial.write(deviceId); break;
      }
      if (motor != -1) {
        motorGo(motor, direction, speed);
      }
      command = 0;
      lastCommandTime = millis();
    }
  } else {
    if (millis() - lastCommandTime > timeoutMillis) {
      motorGo(0, BRAKEGND, 0);
      motorGo(1, BRAKEGND, 0);
    }
  }
  
  // if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) < CS_THRESHOLD))
}


/* motorGo() will set a motor going in a specific direction
 the motor will continue going in that direction, at that speed
 until told to do otherwise.
 
 motor: this should be either 0 or 1, will selet which of the two
 motors to be controlled
 
 direct: Should be between 0 and 3, with the following result
 0: Brake to VCC
 1: Clockwise
 2: CounterClockwise
 3: Brake to GND
 
 pwm: should be a value between 0 and 255 */
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
  if (motor <= 1)
  {
    if (direct <=4)
    {
      // Set inA[motor]
      if (direct <=1)
        digitalWrite(inApin[motor], HIGH);
      else
        digitalWrite(inApin[motor], LOW);

      // Set inB[motor]
      if ((direct==0)||(direct==2))
        digitalWrite(inBpin[motor], HIGH);
      else
        digitalWrite(inBpin[motor], LOW);

      analogWrite(pwmpin[motor], pwm);
    }
  }
}


/**
 * Divides a given PWM pin frequency by a divisor.
 * 
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *      o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *        256, and 1024.
 *      o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *        128, 256, and 1024.
 * 
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired on timer0
 *   - Pins 9 and 10 are paired on timer1
 *   - Pins 3 and 11 are paired on timer2
 * 
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 * 
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
 */
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}
Reply With Quote
  #3  
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
  #4  
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
  #5  
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
  #6  
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 11:11 PM.


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