Get arm position on startup


#1

Hello,
I am starting to work through mblock stuff, and have done arduino programming in the past. The question is, how do i know what position the arm is in when the robot starts up? I am using MeEncoderOnBoard to do this. As near as i can tell, the position is always zero on startup.
I am really hoping i missed something simple here, otherwise this is going to be a pain. Ideas?

Thanks,
Cade


#2

I had the same problem. I am beginner so maybe my work around can be simplified but I shall describe what I had done.
I am on Ultimate 2.
As long as I understand, being a beginner, there is no possibility to “read” the starting-up position of an encoder motor. So I installed an ultrasonic sensor HC-SR04 because it is cheaper than Me Ultrasonic Sensor on a holder. I had to modify the holder to allow sensor to be mounted inclinated with 15 degrees relative to horizontal. This inclination was necessary because when the arm is in the highest position the ultrasonic rays hit the track and not the floor.
I used NewPing library because I wanted to use the 4 pins sensor (+5V, Trig, Echo, GND) like a 3 pin sensor (+5V, Trig+Echo, GND). This was necessary because I have more sensors on my RoboticArmTank and I didn’t want to use 2 signal pins on MegaPi for this sensor. For this it is necessary to make a short between pins Trig and Echo from the sensor and to connect them to an only one signal pin on MegaPi board.
All these were done to be able to bring the arm to a certain height when the robot is started.
Assuming that the arm encoder motor is connected to Port 3 on MegaPi board here is my code:


//=========================================================
// Setup Robotic Arm position at about 22 cm from floor
//---------------------------------------------------------
// This code bring the robot arm at about 22 cm from floor.
//
// Arm encoder motor speed is set to 80 rpm.
// Due to motor inertia the arm tend to go over the imposed height limits so
// I set different height limits when the arm is ascending (limit is 20 cm)
// and when is descending (limit is 23 cm).
//----------------------------------------------------------

// read the actual arm height
NewPing sonar_arm_height(TRIGGER_PIN_Arm_Height, ECHO_PIN_Arm_Height );
Arm_Height = sonar_arm_height.ping_cm();

// If actual arm height from floor is over 23 cm

if ((Arm_Height) > (23))
{
Serial.print("initial height: ");
Serial.println(Arm_Height);
Encoder_3.runSpeed(80);

 while (!((Arm_Height) < (23)))
 {
   Arm_Height = sonar_arm_height.ping_cm();
   Serial.print("height in while loop: ");
   Serial.println(Arm_Height);
   delay(50);
   loop();
 }
 Serial.println("stop arm encoder motor");
 Encoder_3.runSpeed(0);

}

//If actual arm height from floor is under 20 cm

if ((Arm_Height) < (20))
{
Serial.print("initial height: ");
Serial.println(Arm_Height);
Encoder_3.runSpeed(-80);

while (!((Arm_Height) > (20)))
{
  Arm_Height = sonar_arm_height.ping_cm();
  Serial.print("height in while looo: ");
  Serial.println(Arm_Height);
  delay(50);
  loop();
}
Serial.println("stop arm encoder motor");
Encoder_3.runSpeed(0);

}

// End Setup Robotic Arm position
//================================================


You have to add this piece of code in void setup().
Assuming that Trig+Echo sensor pin is connected to pin A9 (you have to change this pin as in your project) from MegaPi Board you have also to add in the beginning next declarations:


// Prepare serial print
Serial.begin(115200);

// Define variable Arm_Height
int Arm_Height = 0;

// Load NewPing library
#include <NewPing.h>

// Define pins for arm ultrasonic sensor
#define TRIGGER_PIN_Arm_Height A9 // Arduino pin for both trig and echo
#define ECHO_PIN_Arm_Height A9 // Arduino pin for both trig and echo


In this way, when you start robot, arm will move to 20-23 cm from floor.
I think is a good starting point.
Any comments and corrections are welcome.
In following photo you can see the ultrasonic sensor, the modified holder and the way of installation.


#3

I see that you have one pointed down and are using it to check distance to floor. Any particular reason you didn’t use 2 switches, one at min height, and one at max height?
I am doing more of a Wall-E style robot for a county fair :wink:
Cade


#4

There are more reasons for which I used Ultrasonic sensor:

  1. and the most important reason is that using ultrasonic I am using only one pin from MegaPi boatrd.
  2. is I should use switches I should have to use two pins from MegaPi board and I should get only two info … arm is at minimum height and arm is at maximum height but the real position of arm from floor I should never know.
  3. using ultrasound I am using only one pin from MegaPi board and full control of arm height.
    So I think that I had enough reasons to use ultrasound and not switches.

#5

I picked up the Angle sensor to work on the angle the arm is at. Seems to work well, needed to slightly modify the shaft to fit the sensor. Works good, though.