DC motor Position control with joystick

Hi all,
I am building an excavator and I will like that when I set a position for my bucket via my joystick that it stays in that position even when there is a load attached to it that is causing it to move. In other words, when I set my angle on the servo, if the angle moves out of place due to a disturbance and not my joystick, I will like the arm to move back to that angle it was at originally.

Do I need to get feedback from the servo? and compare it somehow? What should I do to achieve this?

Below is my code for controlling the two servos with my joystick. It works by after i move the joystick to a position and release it the servo angle stays on that position untill i move the joystick again (i.e the centre position does not move it back to its original 90 degree position when the joystick is released)

#include <Servo.h>

#define mainArm 0
#define jib 1
#define bucket 2
#define slew 3

Servo servo[4];      //code used for attaching upto 4 servos

byte angle[4] = {90, 90, 90, 90};       // middle point for servo angle

byte potPin[4] = {A0, A1, A2, A3};  // input pins to attach your potentiometers
byte servoPin[4] = {7, 6, 10, 9};    // input pins to attach servos

void setup() {

  Serial.begin(9600);
  Serial.println("Starting DiggerCode.ino");


  for (byte n = 0; n < 4; n++) {
    servo[n].attach(servoPin[n]);
  }
}

void loop() {
  readPotentiometers();
  moveServos();
  delay(10);
  
}

void readPotentiometers() {
  int potVal;
  for (byte n = 0; n < 4; n++) {
    potVal = analogRead(potPin[n]);
    
    if (potVal < 200) {         // dead zone for the joystick I used is 200 to 550.
      angle[n] += 1;
      if (angle[n] > 170) {
        angle[n] = 170;
      }
    }
    
    if (potVal > 550) {         // deadzone upper value
      angle[n] -= 1;
      if (angle[n] < 10) {
        angle[n] = 10;
      }
    }

  }
}

void moveServos() {
  for (byte n = 0; n < 4; n++) {
    servo[n].write(angle[n]);
  }
}

EDIT: I no longer am required to use servos instead, I must use linear actuators for the excavator according to my project supervisor. However these are very expensive, nevertheless instead of buying one, I am thinking of making them. The following link is where I am turning towardshttp://www.instructables.com/id/Quick-and-easy-electric-cylinder-prototype-.../. These linear actuators are to be inserted in a toy excavator as shown in the link http://www.amazon.com/Bruder-02439-Toys-Caterpillar-Excavator/dp/B00024QOUO/ref=sr_1_1?ie=UTF8&qid=1412193602&sr=8-1&keywords=bruder+excavator. I was thinking they should replace the existing hydraulic look alike actuators. My question is, can the mini DC motor be controlled with the Joystick on arduino? I figured it maybe just a case of switching polarities for up and down motions :confused: not too sure. Also does anyone have any other recommendation that I should take to move the arms and boom on a toy excavator? Also if there is any disturbance from the load that changes the position of the bucket is there a way to auto control the bucket back to its intended position (position control)

See

Izzy92:
In other words, when I set my angle on the servo, if the angle moves out of place due to a disturbance and not my joystick, I will like the arm to move back to that angle it was at originally.

Do I need to get feedback from the servo? and compare it somehow? What should I do to achieve this?

But you don't actually "set" the angle do you, in the sense of knowing the servo must go to say 32 degrees.... you move the end with the joystick until it's in the "right" place, the actual value is irrelevant.

A feedback servo such as ada's 1404 isn't going to help in this case. You haven't positioned the end by by a specific degree value that you know as a number: in that case yes a feedback servo wold confirm safe arrival. You're positioning under control of your eyeball and the joystick, so you know it already got to the right spot.

If a disturbance is capable of moving the end while it's under the 50Hz pulsing control of the Arduino, then you have the wrong servo in the first place. No amount of control is going to return the end to where it was, if the applied torque is more than the motor's.

If the disturbing load isn't capable of actually moving the already successfully positioned end, then the normal pulsing control will keep the servo in place anyway.

The feedback servo is only of use where you say "go to 27 degrees" and read the feedback signal to see it actually got there (or not, of course.)

edit... ps: see the first post in my thread here for oscilloscope trace as evidence of the 50Hz holding pulse from Arduino

Izzy92:
In other words, when I set my angle on the servo, if the angle moves out of place due to a disturbance and not my joystick, I will like the arm to move back to that angle it was at originally.

Servos do this automatically - it's what they are for.

If the servo loses position then you need a more powerful servo.

WHY, oh WHY have you started a THIRD thread (is it only 3) about your excavator project ??????

Keep it all together so we can see everything about the project in a single place.

...R

ants on an elephant ?