Robot Arm Brushed DC motor feedback position

Hello

I have a Robotic Arm Kit and a arduino uno,
This my first project so lots to learn.

I am trying to write code to control just one axis (for now) of my robotic arm.
I have attached potentiometer to the arm to provide feedback pin A0.
And I have another control potentiometer to set the required position A1,

I am half way with my code but cant get the math to work, I trying to get the the control pot to offset the position pot.

This is my code, It would be greatly appreciated if someone could point me in the right direction.

//Project Arm..........



//motor sheild output Pins
const int enableM3 = 6;//using PWM on enable to control speed
const int xM3 = 4;// move motor
const int yM3 = 7; // move motor





//Pots inputs
const int axis3pot = A0;// Axis 3 position pot 
const int controlpot = A1;//Control pot input




//number storage
int axis3position;//stores axis3pot value
int controlpotposition;//stores controlpot value 

//Storage after mapping
int controlmaped_X;// stores X control number
int controlmaped_y;//stroes Y control numbers


// Maped and constrained 
int requestedpos1;// stores pot minus maped X
int requestedpos2;// stores pot minus maped X plus mapedY










void setup() {
 // pin setup in or out put..................
 pinMode(enableM3, OUTPUT);//PWM axis 3
 pinMode(xM3, OUTPUT);// mmove motor
 pinMode(yM3, OUTPUT);//move motors
 pinMode(axis3pot, INPUT);// Axis 3 position  Pot
 pinMode(controlpot, INPUT);// Control pot input
 
 
 
 
 
 //Serial Code...................
  delay (2000);
 Serial.begin( 9600 );
 delay (2000);
 Serial.println("Hello Brian");
 delay(1000);
 Serial.println("How are you today?");
 delay(2000);
 
 
}









// let the loop begin .........................
void loop() {
 
 int  axis3position = analogRead (axis3pot);//read axis pot and store it in axis3poition
 int  controlpotposition = analogRead (controlpot);//read controlpot and store in controlpotposition
 
 //Mapping Values
 controlmaped_X = map(controlpotposition,0,511,511,0);// X axis mapping
 controlmaped_X = constrain(controlmaped_X, 0, 511);
 controlmaped_y = map(controlpotposition,512,1023,0,511);// Y axis mapping
 controlmaped_y = constrain(controlmaped_y, 0, 511);
 
 requestedpos1 = axis3position - controlmaped_X;
 requestedpos1 = constrain(requestedpos1, 0, 1023); 
 
 requestedpos2 = requestedpos1 + controlmaped_y;
 requestedpos2 = constrain(requestedpos2, 0, 1023);
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 //..........Serial Code.......................................
 // Pot position
 Serial.print("Axis 3 Pos   ");
 Serial.print(axis3position);
 Serial.print("    Control Pot Pos   ");
 Serial.print(controlpotposition);
 Serial.print("   Maped X   ");
 Serial.print(controlmaped_X);
 Serial.print("   Maped Y   "  );
 Serial.print(controlmaped_y);
 Serial.print("   Req1   ");
 Serial.print(requestedpos1);
 Serial.print("   Req2   ");
 Serial.println(requestedpos2);
 
 

}

#7 below for how to better post your code in code boxes. What are you using for a motor driver?

http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks for the advice Zoomkat I have modified the original post.

I am using a Freetronics HBRIDGE Dual Channel H-Bridge Motor Driver Shield.

HBRIDGE-orthogonal_medium.jpg

You define axis3position as a global variable in your sketch, and then define another variable of the same name inside loop( ). That won't work.

All that mapping and constraining doesn't make any sense to me. What are you actually trying to do ?