Robotic arm homing
I'm making a humanoid robotic arm and so far i've designed the shoulder. for rotation I've been using a high torque dc motor with an encoder that has a hall sensor and uses 17 pulses for one complete rotation along with a gear box that has a gear ratio of 1:625 making total pulses to (625x17). Now the robotic arm shoulder should only moves around 90 degrees making the pulses (625x17x0.25 = 6256.25). I'm controlling this dc motor with an Arduino and an L298 H-bridge module for controlling the motor. I've written a code using the Arduino IDE and I am still a beginner at this.
The main premise here is to do the homing of the shoulder. Basically when the robot turns on first it moves in the counter clockwise direction looking for the limit switch and then from their start counting the pulses to reach 90 degrees (6256.25 pulses) clock wise.
The main problem here is that after pressing the limit switch the motor starts to rotate in the clockwise direction after hitting the limit switch but it does not stop after reaching 90 degrees.
Any help is highly appreciated. Im new to coding as well as stack overflow.
#define Encoder_output_A 2
#define Encoder_output_B 3
int y;
int pos = 0;
int motorpin1=5;
int motorpin2=4;
float Count_pulses = 0;
float Count_rounds = 0;
int Limswitch = 7;
void setup() {
Serial.begin(9600); // activates the serial communication
pinMode(Encoder_output_A,INPUT); // sets the Encoder_output_A pin as the input
pinMode(Encoder_output_B,INPUT); // sets the Encoder_output_B pin as the input
attachInterrupt(digitalPinToInterrupt(Encoder_output_A),DC_Motor_Encoder,RISING);
pinMode(motorpin1,OUTPUT);
pinMode(motorpin2,OUTPUT);
pinMode(Limswitch,INPUT);
homing();
}
void loop() {
Serial.print("Result: ");
Serial.println(Count_pulses);
Serial.println(Count_rounds);
delay(100);
y=digitalRead(Limswitch);
if(y==LOW ||Count_pulses>=2656.25)// 17 x 625 x 0.25 = 2656.25
{digitalWrite(motorpin1,LOW);
digitalWrite(motorpin2,LOW);
} else{
digitalWrite(motorpin1,HIGH);
digitalWrite(motorpin2,LOW);
}
}
//The purpose of this code is to count the ouput pulses or the encoder outputs as you rotate the Motor shaft.
void DC_Motor_Encoder(){
int b = digitalRead(Encoder_output_B);
if(b > 0){
Count_pulses++;
Count_rounds = Count_pulses/17;
}
else{
Count_pulses--;
}
}
void homing() {
y=digitalRead(Limswitch);
if(y==HIGH && Count_pulses==0)
{while(y==HIGH){digitalWrite(motorpin1,HIGH);
digitalWrite(motorpin2,LOW);
y=digitalRead(Limswitch);
}
}
else if(y==LOW){
while(Count_pulses < 2657){
digitalWrite(motorpin1,LOW);
digitalWrite(motorpin2,HIGH);
}
}
if(Count_pulses>=2656.25)
digitalWrite(motorpin1,LOW);
digitalWrite(motorpin2,LOW);
}
Comments
Post a Comment