Let's Make Robots!

IK programming for Arduino?

Everything seems working now for quadbot:

Now, the programming is the diffecult part for me. Anyone can show me which direction I should go for IK programming or any book I should read to understand the concept?

Thanks a lot!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

By the way, the servo goes pretty fast. instead of delay() time; can I set the speed for servo? I couldn't find such setting in servo.h library to control the speed.

To slow down a servo, you need to send intermediary positions. The more intermediary positions you send, the slower the servo will move. There is a way to do this automatically by using a procedure called interpolating. It uses floating point math, but Arduino can do it easy. You basically need to tell the procedure the current position, the target position and the speed (how many intermediary positions). Here is an example for one servo:

void Servo1_move(int start_pos; int end_pos; int speed){
   for (j=0;j<Speed;j++){
    per_a = ((float)(Speed-j)) / ((float)Speed);
    per_b = (float)1.0-per_a;
    sv1_pos=start_pos*per_a + end_pos*per_b;
    servo1.write(sv1_center + sv1_pos);
  }
}

For a gait move, it`s more complicated, but it is done using an array of steps for each servo.

I am confused about how this would work. The code would come up with the increments, but it looks like you give it new positions without knowing if it has gotten to the previous position.

Unless you hack the servo and get feedback from the potentiometer, there is no way to know if it reached the desired position. Sure, if you use special servos like the Bioloid Ax or Rx series or an OpenServo, you have this possibility. But a standard analog hobby servo likes to keep the positioning info to itself.

The code only generates as many intermediary positions as you want to slow down the servo movement. If you need to know if the appendage connected to the servo encounters an obstacle, you need to add sensors to that appendage. Then write the code to run in a loop that checks the sensor(s) at every iteration. If you use contact sensors, you can wire them in series with different resistor values and connect them to a single analog pin. Depending on the sensor that is triggered, you will get a different voltage level, so you can monitor say 6 leg sensors for a hexapod easy. For position feedback, you can use bend sensors installed along the leg for example, then you will get a different voltage depending on the position of the leg, but this uses one analog pin per bend sensor.

I don't think the OP needs a sensor; he is pretty sure the servo will be done before he needs it to be. Despite my stated distaste for the delay function, I think he could use it in conjunction with a mod to your suggested code:

void Servo1_move(int start_pos; int end_pos; int duration){

  long lDelay = (long) ( (float) duration / (float) abs(start_pos - end_pos) + 0.5);

  int iAdj = abs(start_pos - end_pos) / (start_pos - end_pos);

   for (j=start_pos;j != end_pos;j =  j + iAdj ){

    servo1.write(sv1_center + j);

    delay (lDelay);
  }
}

I have look into the hexapod code done by Xen. Yes, it has LOTS of arrays to do the gait. Thanks for the code. How's your robot coming?

AFAIK, you buy your servo to run at the speed you want and you use the servo library to say what angle to set it to and it always goes there at the same speed. To go slower, you would have to set it to increasing or decreasing amounts in loop() sort of like fading an LED. Then it would be jerky, but if the jerks are small enough they would (hopefully) not be noticeable.

EDIT - BTW, I abhor the use of delay. Look at using millis() and storing the current value at the time you set something to one state and then in the main loop do "if (millis() - ulLastTime) > ulInterval)" processing to see if it is time to change it yet. If it is really important that it be exact, then delay can't be helped, but you may still use the interval technique to get close and only delay when the remaining time falls under some threshhold. There is usually something else it could be doing.

 

Hum...seems like a lot of math to do and try out! Thanks for advice!

The picture you posted is from a Mini controller, not an ArbotiX controller. The Mini uses a Mega168 and the ArbotiX uses a Mega644 (40 pin DIP). The Mini is designed mostly for wheeled robots, just like my uBotino board and the ArbotiX is designed for Bioloid servo based robots. You can't use regular servos with the ArbotiX, but you can tweak the "special pypose sketch" code to work on an Arduino Mega board using the Servo library. Then you can use the Pypose and Nuke. I'll try to adapt the pypose sketch to work on a servo board I'm working on (Mega328, up to 12 low power servos). I would rather use Processing instead of Python, but I am not such a good programmer to re-write the gait designer and IK engine already implemented in Pypose and Nuke.

Thanks for correction. I was thinking the same thing to re-code it for arduino IDE. You were right, Processing should be better for such works.

By the way, how do you think of Picaxe for biped? I am planning to try my next biped in picaxe since people were saying it could handle multiple servos and easy for coding?