Author Topic: How can i make this program ?  (Read 2590 times)

0 Members and 1 Guest are viewing this topic.

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
How can i make this program ?
« on: March 12, 2010, 11:21:52 AM »
I am programming my hexapod, here is how i defined the servos and drivers.

Code: [Select]
SERVO Leg1_servo_1 = MAKE_SERVO(FALSE, G5,1500, 500);
SERVO Leg1_servo_2 = MAKE_SERVO(FALSE, E4,1500, 500);
SERVO Leg1_servo_3 = MAKE_SERVO(FALSE, E5,1500, 500);
SERVO Leg2_servo_1 = MAKE_SERVO(FALSE, E6,1500, 500);
SERVO Leg2_servo_2 = MAKE_SERVO(FALSE, H3,1500, 500);
SERVO Leg2_servo_3 = MAKE_SERVO(FALSE, H4,1500, 500);
SERVO Leg3_servo_1 = MAKE_SERVO(FALSE, H5,1500, 500);
SERVO Leg3_servo_2 = MAKE_SERVO(FALSE, B4,1500, 500);
SERVO Leg3_servo_3 = MAKE_SERVO(FALSE, B5,1500, 500);
SERVO Leg4_servo_1 =MAKE_SERVO(FALSE, B7,1500, 500);
SERVO Leg4_servo_2 =MAKE_SERVO(FALSE, H7,1500, 500);
SERVO Leg4_servo_3 =MAKE_SERVO(FALSE, G3,1500, 500);
SERVO Leg5_servo_1 =MAKE_SERVO(FALSE, L0,1500, 500);
SERVO Leg5_servo_2 =MAKE_SERVO(FALSE, L1,1500, 500);
SERVO Leg5_servo_3 =MAKE_SERVO(FALSE, L3,1500, 500);
SERVO Leg6_servo_1 =MAKE_SERVO(FALSE, L4,1500, 500);
SERVO Leg6_servo_2 =MAKE_SERVO(FALSE, L6,1500, 500);
SERVO Leg6_servo_3 =MAKE_SERVO(FALSE, L7,1500, 500);
//SERVO servo_3 = MAKE_SERVO(FALSE, H5, 1500, 500);

//SERVO digital_example = MAKE_SERVO(FALSE, H5, 1520, 910);//digital servos have greater range

// Create the list - remember to place an & at the
// start of each servo name
SERVO_LIST servo1[] = {&Leg1_servo_1};
SERVO_LIST servo2[] = {&Leg2_servo_1};
SERVO_LIST servo3[] = {&Leg3_servo_1};
SERVO_LIST servo4[] = {&Leg4_servo_1};
SERVO_LIST servo5[] = {&Leg5_servo_1};
SERVO_LIST servo6[] = {&Leg6_servo_1};
SERVO_LIST servo7[] = {&Leg1_servo_2,&Leg1_servo_3};
SERVO_LIST servo8[] = {&Leg2_servo_2,&Leg2_servo_3};
SERVO_LIST servo9[] = {&Leg3_servo_2,&Leg3_servo_3};
SERVO_LIST servo10[]= {&Leg4_servo_2,&Leg4_servo_3};
SERVO_LIST servo11[]= {&Leg5_servo_2,&Leg5_servo_3};
SERVO_LIST servo12[]= {&Leg6_servo_2,&Leg6_servo_3};

// Create a driver for the list of servos
SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servo1);
SERVO_DRIVER bank2 = MAKE_SERVO_DRIVER(servo2);
SERVO_DRIVER bank3 = MAKE_SERVO_DRIVER(servo3);
SERVO_DRIVER bank4 = MAKE_SERVO_DRIVER(servo4);
SERVO_DRIVER bank5 = MAKE_SERVO_DRIVER(servo5);
SERVO_DRIVER bank6 = MAKE_SERVO_DRIVER(servo6);
SERVO_DRIVER bank7 = MAKE_SERVO_DRIVER(servo7);
SERVO_DRIVER bank8 = MAKE_SERVO_DRIVER(servo8);
SERVO_DRIVER bank9 = MAKE_SERVO_DRIVER(servo9);
SERVO_DRIVER bank10 = MAKE_SERVO_DRIVER(servo10);
SERVO_DRIVER bank11 = MAKE_SERVO_DRIVER(servo11);
SERVO_DRIVER bank12 = MAKE_SERVO_DRIVER(servo12);

Now in my main program, i have a loop that checks for input from the PC.

When i press "f" the hexapod should move forward. This requires many servos to be running.When i use the act_speed command one after another for each servo,it causes the axon II to reset, always. When i put delay_ms(20) after each act_speed command, the axon resets but rarely. Because the time taken for each servo to move to the position required might differ and the delay is not enough.

Now forget about the above and help me do the following, once i know how to do it, then i can change it to suit my hexapod.

Suppose that i want to move all 18 servos, one after another:
i want to do it this way, first to have an array

array1=[18]={&Leg1_servo_1,Leg1_servo_2...........etc.. for all 18 servos}; //i dont know how to do this
int j=1;
int speed=50;
for(j=1;j<=18;j++);
act_setSpeed(array1[j],speed);

int x=act_getSpeed(array1[j]);

if (x==speed) //to check if the servo reached its position

i want like a while loop, where the loop continues until x==speed, once this is achieved then continue the for loop.

« Last Edit: March 12, 2010, 01:44:02 PM by bilals »

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: How can i make this program ?
« Reply #1 on: March 12, 2010, 12:05:34 PM »
I'm not very familiar with the servo part of webbot lib, but I'm pretty sure that act_getSpeed() will not return you the actual position of the servo but will rather return the last speed you set with act_setSpeed(). There is no feedback from a servo to the MCU regarding its current position.

Moreover, if the axon resets when you try to run all servo, there is probably a power issue. You need to solve that before anything else.

Chelmi.

Offline Hasan999

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Re: How can i make this program ?
« Reply #2 on: March 12, 2010, 12:28:46 PM »
here is how i defined the servos and drivers.

Nope, that is how I defined them  ;D lol

Quote
axon II resets

Assuming that with a few servos, it doesn't reset, you really need to buy better ####mAh battery, (maybe 3600mAh to 5000mAh would work). You should try to solve the power problem through replacement of battery... programming would not help much (believe me).

btw, I am not 100% sure, but (please try and check) that even if you do NOT put act_speed commands at all... WebbotLib will still give these commands in background continuously (with a speed of '0')... so even if you're keeping 1 command in a loop, it wont make a difference.

you might wanna try using servosDisconnect and servosConnect commands (as I mentioned in your other post) to improvise somehow. [yes, this will stop giving signals to the servo(s), but then, they would be loose, won't your robot collapse? - its heavy isn't it]

As chelmi, I would also suggest, buy better batteries first, and then it would be easier to solve problems through programming.

Good Luck.






Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #3 on: March 12, 2010, 01:41:57 PM »
I'm not very familiar with the servo part of webbot lib, but I'm pretty sure that act_getSpeed() will not return you the actual position of the servo but will rather return the last speed you set with act_setSpeed(). There is no feedback from a servo to the MCU regarding its current position.
Chelmi.

I think (I am not sure) that act_setSpeed() for a servo will tell the servo to which position to move rather than how fast to move. If this is the case then act_getSpeed() will return the position of the servo.

Nope, that is how I defined them  ;D lol
;D ;D ;D, In fact you're right.

I have two 2300mAh batteries, I'll try to connect both to Axon II and see if that helps.

btw, I am not 100% sure, but (please try and check) that even if you do NOT put act_speed commands at all... WebbotLib will still give these commands in background continuously (with a speed of '0')... so even if you're keeping 1 command in a loop, it wont make a difference.

I am still programming the hexapod without the servos being attached to the chassis & legs (not yet fabricated). But, what you're saying might be true as after i switch the axon >> all servos are centered >> after that strange sounds (i dont know how to describe it) is constantly being produced by all servos + by holding the servos (with hand) you can feel vibrations. I still have to fabricate the hexapod parts (chassis + legs) and attach servos and then test it to be sure.


Thanks guys, but forgetting about the resetting of the Axon, can you please help me with the program i mentioned earlier. Even if it doesnt help in my problem. I'd like to know how to do such arrays+loops in combination with if statements, as i am still learning the programming commands.


Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: How can i make this program ?
« Reply #4 on: March 12, 2010, 01:55:33 PM »
I'm not very familiar with the servo part of webbot lib, but I'm pretty sure that act_getSpeed() will not return you the actual position of the servo but will rather return the last speed you set with act_setSpeed(). There is no feedback from a servo to the MCU regarding its current position.
Chelmi.

I think (I am not sure) that act_setSpeed() for a servo will tell the servo to which position to move rather than how fast to move. If this is the case then act_getSpeed() will return the position of the servo.

Yes, act_setSpeed() is more like an act_setPosition() when used for a servo. But my comment is still valid. act_getSpeed() (or act_getPosition) will return you the value you passed to the last call of act_setSpeed(). NOT the current position of the servo. I just checked the documentation:

Quote
act_getSpeed
DRIVE_SPEED act_getSpeed(const __ACTUATOR_COMMON* act)
Returns the last value from 'act_setSpeed'.
NB This is not the actual speed that the actuator is moving at - we have no way of knowing
that without an encoder!

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #5 on: March 12, 2010, 02:02:19 PM »
Yes, act_setSpeed() is more like an act_setPosition() when used for a servo. But my comment is still valid. act_getSpeed() (or act_getPosition) will return you the value you passed to the last call of act_setSpeed(). NOT the current position of the servo. I just checked the documentation:

Oh OK, i got it now. Thanks chelmi.

But suppose now that it gives you its actual position. How can i complete the program. This is just to learn how the commands works.

Offline Hasan999

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Re: How can i make this program ?
« Reply #6 on: March 12, 2010, 04:13:10 PM »
3 small things to clarify:

1) When you connect two batteries in parallel... make sure (using Voltmeter, etc) both the batteries have exactly the same voltage at that time. (I'm pretty sure you'd kno that, but its better to warn  8) )

2) The vibrations or noises you hear, I am pretty sure if you use only 12 servos in 12 different banks, they won't vibrate at all) - that is the reason I have been begging my friend Webbot to enable the use of 8-bit timers.

So please try to //remove the commands for servo 3 from each leg ! - i.e. program it as if you had only 12 servos, and let me know if you notice any difference)

3) I would agree with chelmi, as "x=act_getSpeed(array1[j]);" doesn't make sense to me...

I would recommend using another set of (array of) variables for "desired positions"... for example:

While having: act_getSpeed(array1[j],speed); keep on looping

lets say initially: speed = 0;
desired position you set as:  ds1 = 50;

now you can compare, if (speed<ds1) { speed+=1; }

so speed (that is the position) will keep on increasing by '1' in each loop, until it reaches the desired position.

I am not even sure if that is what you wanted... but hope that helps  :P

Hasan.

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #7 on: March 12, 2010, 05:05:54 PM »
1) When you connect two batteries in parallel... make sure (using Voltmeter, etc) both the batteries have exactly the same voltage at that time. (I'm pretty sure you'd kno that, but its better to warn  8) )

I might disappoint you, but i didnt really know. The batteries are exactly the same. Shall i fully charge both of them before connecting them to the Axon ?

2) The vibrations or noises you hear, I am pretty sure if you use only 12 servos in 12 different banks, they won't vibrate at all) - that is the reason I have been begging my friend Webbot to enable the use of 8-bit timers.

So please try to //remove the commands for servo 3 from each leg ! - i.e. program it as if you had only 12 servos, and let me know if you notice any difference)

The magnitude of the vibration is sooooo small that you cant even notice it by looking. By touching the servos you'll feel the vibration, but again its undisturbing. When i first received the Axon, I connected one servo only, but same vibration and noise was produced. I was looking around and i found that this sound is produced by the servos as it is always trying to center its position (as you previously said, running in the background).
To confirm, I attached a load to the servo, the servo rotated under this load (Axon switched off). As I turn the power on, the position of the servo becomes centered and the load can no longer rotate the servo.

3) I would agree with chelmi, as "x=act_getSpeed(array1[j]);" doesn't make sense to me...

I would recommend using another set of (array of) variables for "desired positions"... for example:

While having: act_getSpeed(array1[j],speed); keep on looping

lets say initially: speed = 0;
desired position you set as:  ds1 = 50;

now you can compare, if (speed<ds1) { speed+=1; }

so speed (that is the position) will keep on increasing by '1' in each loop, until it reaches the desired position.

I am not really concerned about the position and speed at this point. I just want to know the following:

1)Can you define an array with characters rather than numbers, as in this:
   int array[2]={bank1,bank2} rather than arrays being int array[2]={1,2}

2)What is the correct way to use the while loop? An easy example would help.


Thanks Hasan for your help.
« Last Edit: March 12, 2010, 05:08:27 PM by bilals »

Offline Hasan999

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Re: How can i make this program ?
« Reply #8 on: March 13, 2010, 02:47:36 AM »
I know you're worrying more about the programming than the electrical problem, but its always better to get rid of one first.

For connecting them in parallel... do one thing:

1) Charge both of them fully (equally)
2) Leave them for like 15 min (because it discharges a small amount, especially right when you remove it from charging)
3) Very important: check the voltage of both of the batteries,

Lets say you get Battery A = 6.88V  and Battery B = 6.78V

Now, use Battery A (either Axon, or elsewhere) so that it reduces and settles to 6.78V same as Battery B.

A difference of ±0.02V would not trouble much, however, a difference of ±0.1V or higher, would damage the batteries (life and efficiency).

4) Once you have both batteries of same Voltage, connect black to black, red to red... and re-charge.

-----------------------------

For the arrays having banks, I am really not sure ! you'll have to try things, until someone with a good programming skills comes here to help you. (I think you'll need to use banks with reference: *bank1,*bank2 etc. - but again, not sure)

-----------------------------

Quote
Thanks Hasan for your help.

You're welcome  :)

------------------------------

Hasan.
« Last Edit: March 13, 2010, 02:50:07 AM by Hasan999 »

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #9 on: March 13, 2010, 07:47:48 AM »

4) Once you have both batteries of same Voltage, connect black to black, red to red... and re-charge.


What do you mean : connect black to black, red to red (i know you mean the wires) but connect what to what ?

Do i have to do this every time i charge the batteries ?

Offline Hasan999

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Re: How can i make this program ?
« Reply #10 on: March 13, 2010, 08:04:50 AM »
I meant, you will have to cut the cables for (probably) both, and connect black to black and red to red...

I have also illustrated the same in a paint file (attached).

Then you will have 1 combined battery of 6V, 3600mAh ! 4600mAh
« Last Edit: March 13, 2010, 08:50:37 AM by Hasan999 »

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #11 on: March 13, 2010, 08:16:53 AM »
Thanks for the illustration, that was GREAT  ;).

Is it 3600mAh or 4600mAh (2*2300)? This is considered 1 battery and when charging, it will charge both equally, right ?

So, i dont have to desolder the pins (i dont know if you saw the Axon II MCU power selection video):

Axon II MCU Power Selection
« Last Edit: March 13, 2010, 08:19:58 AM by bilals »

Offline Hasan999

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
Re: How can i make this program ?
« Reply #12 on: March 13, 2010, 08:49:16 AM »
Quote
Is it 3600mAh or 4600mAh (2*2300)?

Ops, my bad... yes, for 2300mAh each, you will give you maximum of 4600mAh.

and since I use Axon 1, i really did not see this video before....

but, don't you think combining batteries would be still better?..since you'll have to charge only 'once' for both !?

please clarify this with someone else though.

Offline bilalsTopic starter

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 0
Re: How can i make this program ?
« Reply #13 on: March 13, 2010, 08:59:00 AM »

but, don't you think combining batteries would be still better?..since you'll have to charge only 'once' for both !?


Yeah, you're right, it is much better combining them. And since it works fine for you, I'll combine them.

 


Get Your Ad Here

data_list