It has been a long journey, filled with knowledge. At this point, my RARM is almost done.
I would like to tell you a little bit of what was my path to building the robot.
Let's get started
- In the beginning, when I started blogging I used some servo motors to learn more about mechanical parts how they should move and how axis interact with each other avoiding blocking stages. That leads me to make a mixture between servo motors and steppers. Servos can be easy to control but sometimes they are not as stable as a servo can be in stressful situations.
- Modeling, I am not a mechanical engineer so I had a really stressful time making pars at the end my design was not as efficient as others so I want to recognize the job made by JjRobots which design was taken from and to How to Mechatronics, without their orientation this could not be done, they knew more about movement and mechanisms, They have lots of information about libraries and how to use other drivers in order to make this type of robot more reliable. In the end, I took their ideas but wanted to improve or make them easy to understand and make more robots like mine for students so they can also get inspired in continuing with these activities.
- Once I had a clear idea time for assembling was coming I'll talk about some problems I had in my last blog with my final presentation.
- Coding, as I said in previous blogs, I was almost using a library but someone in the community advised me about using libraries that could not be as easy to troubleshoot as my own code should be. So taking that In mind I used my own code to create movement, and in my first blog I used a Joystick to control the prototype as a final result, I kept with the idea of using joysticks because it is a friendly way of controlling and if anyone wants to move it they can easily control it with any sophisticated interfaces.
Now here is my code
In the first stage, I just defined variables that will be used in the rest of it, nothing out of this world simple integers and some constants that will be used in the routines I created to be part of the movement.
At the main loop I just called a function called "joystick" this was made in order to keep a clean loop and make my routines.
Here we can see the main structure of the robot, this is a routine that Ill call it as the main movement. I made 2 conditions to map the position of the joystick depending on the axis, then as a parameter for moving the steppers since I used some Drivers we just have to send 2 main parameters which are the direction and the steps,
As extra parameters I send speed in microseconds son in order to have faster movements I have to place a small value in a constant defined at the very beginning, I am Just showing this part of the code because it is almost the same for each stepper (3 steppers) they follow the same structure to that we can keep simple stuff. At the end of this blog, I am attaching the code as plain text. Tomorrow I am uploading the final results and showing the ARM done. There are some phrases in Spanish but they are just to understand me as my main language important stuff is English.
Any doubt or advice is a pleasure to read you.
#include <Servo.h> // Librería para controlar el servomotor
Servo pinza; // variable que tomará el valor de la posición del servomotor
// Stepper Motor X
const int stepPin = 2; //X.STEP
const int dirPin = 5; // X.DIR
// Stepper Motor Extremo
const int stepPinEx = 3; //Y.STEP
const int dirPinEx = 6; // Y.DIR
// Stepper Motor Altura
const int stepPinZ = 4; //Y.STEP
const int dirPinZ = 7; // Y.DIR
// joystick1
int vrx1 = A0;
int vry1 = A1;
int vrx_Joy1 = 0;
int vry_Joy1 = 0;
// joystick2
int vrx2 = A2;
int vry2 = A3;
int vrx_Joy2 = 0;
int vry_Joy2 = 0;
int x = 0;
int y = 0;
int z = 0;
int SMSpeed = 800; // Stepper Motor Speed
void setup() {
// Sets the two pins as Outputs
Serial.begin(9600);
//Contro steppers
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(stepPinEx,OUTPUT);
pinMode(dirPinEx,OUTPUT);
pinMode(stepPinZ,OUTPUT);
pinMode(dirPinZ,OUTPUT);
//stepers
pinza.attach(9); // Se coloca el servo en el pin 2
//control Joystick
pinMode(vrx1 , INPUT);
pinMode(vry1, INPUT);
pinMode(vrx2 , INPUT);
pinMode(vry2, INPUT);
}
void loop()
{
joystick();
}
void joystick()
{
//********************************************************************************** MOVIMIENTO MOTOR X**********************************************
vrx_Joy1 = analogRead(vrx1);
// to stop the stepper motor
if ( (vrx_Joy1 > 490) && (vrx_Joy1 < 510) )
{;}
//AVANZAR MOTOR
if ( vrx_Joy1 > 700)
{
digitalWrite(dirPin,HIGH);
x = x + 1;
digitalWrite(stepPin,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPin,LOW);
delayMicroseconds(SMSpeed);
}
//REGRESAR EL MOTOR
if ( vrx_Joy1 < 300)
{
digitalWrite(dirPin,LOW);
x = x - 1;
digitalWrite(stepPin,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPin,LOW);
delayMicroseconds(SMSpeed);
}
//********************************************************************************** MOVIMIENTO MOTOR BRAZO**********************************************
vry_Joy1 = analogRead(vry1);
// to stop the stepper motor
if ( (vry_Joy1 > 490) && (vry_Joy1 < 510) )
{;}
//AVANZAR MOTOR
if ( vry_Joy1 > 700)
{
digitalWrite(dirPinEx,HIGH);
y = y + 1;
digitalWrite(stepPinEx,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPinEx,LOW);
delayMicroseconds(SMSpeed);
}
//REGRESAR EL MOTOR
if ( vry_Joy1 < 300)
{
digitalWrite(dirPinEx,LOW);
y = y - 1;
digitalWrite(stepPinEx,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPinEx,LOW);
delayMicroseconds(SMSpeed);
}
//********************************************************************************** MOVIMIENTO MOTOR ALTURA**********************************************
vrx_Joy2 = analogRead(vry1);
// to stop the stepper motor
if ( (vrx_Joy2 > 490) && (vrx_Joy2 < 510) )
{;}
//AVANZAR MOTOR
if ( vry_Joy1 > 700)
{
digitalWrite(dirPinZ,HIGH);
z = z + 1;
digitalWrite(stepPinZ,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPinZ,LOW);
delayMicroseconds(SMSpeed);
}
//REGRESAR EL MOTOR
if ( vrx_Joy2 < 300)
{
digitalWrite(dirPinZ,LOW);
z = z - 1;
digitalWrite(stepPinZ,HIGH);
delayMicroseconds(SMSpeed);
digitalWrite(stepPinZ,LOW);
delayMicroseconds(SMSpeed);
}
}