Go Down

Topic: Mega getting stuck! (Read 510 times) previous topic - next topic

Ahmer

Hi, all!

I have a project of humanoid robot. I have written initial code for it to stand stably and walk in straight line. Problem is that when i power on the project, initially my servos moves randomly and not according to uploaded code for at least 3 or 4 mins. During this time, LED (which is connected to pin 13) keeps on blinking and ON LED on Mega remains on. After some time, ON LED remains on but LED connected to pin 13 shuts off until i plug in power again. Any leads?

AWOL

"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

bos1714

Can you post the code you are using, as well as a picture or schematic of your setup?
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

Can you post the code you are using, as well as a picture or schematic of your setup?
I have a LiPo battery which is connected to a buck converter. Converter converts 7.6V from battery to 5.6V (It can supply upto 5A). The output from converter is fed to Arduino mega and all 10 servos(RDS3115mg) separately using supply rails.

Code:
-----------------------------------------------------------
    #include<Servo.h>
   
    Servo RHip;
    Servo RThigh;
    Servo RKnee;
    Servo RAnkle;
    Servo RHigherAnkle;
   
    Servo LHip;
    Servo LThigh;
    Servo LKnee;
    Servo LAnkle;
    Servo LHigherAnkle;
     
    int RHipCenter = 90; 
    int RThighCenter = 130;
    int RKneeCenter = 0;
    int RAnkleCenter = 10;
    int RHigherAnkleCenter = 90;
   
    int LHipCenter = 70;
    int LThighCenter = 70;
    int LKneeCenter = 45;
    int LAnkleCenter = 0;
    int LHigherAnkleCenter = 80;
   
    int d = 15;
    char data;
    void setup()
    {
    Serial.begin(9600);
    RHip.attach(13);
    RThigh.attach(12);
    RKnee.attach(11);
    RAnkle.attach(10);
    RHigherAnkle.attach(7);
    LHip.attach(2);
    LThigh.attach(3);
    LKnee.attach(4);
    LAnkle.attach(5);
    LHigherAnkle.attach(6);
    }
   
    void loop()
    {
    stand();
    delay(5000); 
    walk();     
    }
   
    void stand()
    {
    Serial.println("STAND");
    RHip.write(RHipCenter);
    RThigh.write(RThighCenter);
    RKnee.write(RKneeCenter);
    RHigherAnkle.write(RHigherAnkleCenter);
    RAnkle.write(RAnkleCenter);
    LHip.write(LHipCenter);
    LThigh.write(LThighCenter);
    LKnee.write(LKneeCenter);
    LAnkle.write(LAnkleCenter);
    LHigherAnkle.write(LHigherAnkleCenter);   
    delay(d); 
    }
   
    void walk() {
    Serial.println("WALK");
    leanright();
    leanleft();
    stand();
    }

    void leanleft() {
    RHip.write(RHip.read()-5);
    LHip.write(LHip.read()-5);
    LAnkle.write(LAnkleCenter+5);
    RAnkle.write(RAnkleCenter+5);
    RKnee.write(RKneeCenter+5);
    RHigherAnkle.write(RHigherAnkleCenter+10);
    RHip.write(RHipCenter);
    LHip.write(LHipCenter);
    RThigh.write(RThighCenter);
    }

    void leanright() {
    RHip.write(RHip.read()-5);
    LHip.write(LHip.read()-5);
    LAnkle.write(LAnkleCenter+5);
    RAnkle.write(RAnkleCenter+5);
    LKnee.write(LKneeCenter+5);
    LHigherAnkle.write(LHigherAnkleCenter+10);
    LHip.write(LHipCenter);
    RHip.write(RHipCenter);
    LThigh.write(LThighCenter);
    }
-------------------------------------------------------------

AWOL

#4
Jul 19, 2018, 02:03 pm Last Edit: Jul 19, 2018, 02:03 pm by AWOL
What do the serial prints tell you is happening?

Please remember to use code tags when posting code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

bos1714

When you use the servo.attach(pinNum) function, the servo moves to its middle position (90 degrees for a 180 degree servo). If you want, you can use servo.write() immediately before servo.attach() and it should prevent the sudden jerk.

I also notice that you have no delay in your loop() segment from the end of walk() to the beginning of stand(). Is this intentional?
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

When you use the servo.attach(pinNum) function, the servo moves to its middle position (90 degrees for a 180 degree servo). If you want, you can use servo.write() immediately before servo.attach() and it should prevent the sudden jerk.

I also notice that you have no delay in your loop() segment from the end of walk() to the beginning of stand(). Is this intentional?
Thanks a lot.

I am confused about parameter of delay. I mean how much delay should be added?

bos1714

The delay() function takes in an argument of the number of milliseconds to pause the execution of the program. For instance, "delay(5000)" pauses the program for 5000 milliseconds, or 5 seconds. A nice starting spot is to use the same amount of delay that you use between stand() and walk(). Try adding the same delay after walk() and let me know what happens.
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

The delay() function takes in an argument of the number of milliseconds to pause the execution of the program. For instance, "delay(5000)" pauses the program for 5000 milliseconds, or 5 seconds. A nice starting spot is to use the same amount of delay that you use between stand() and walk(). Try adding the same delay after walk() and let me know what happens.
Not any significant leads this time. I added delay of 50ms in stand() function and called only stand() in loop without any delay. Motors acted appropriately for some small time and started vibrating too and fro then back to appropriate behavior and so goes on.

bos1714

Do you think 50ms is enough? I just noticed that you have the stand() function inside your walk() function as well. Is this intentional?
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

Do you think 50ms is enough? I just noticed that you have the stand() function inside your walk() function as well. Is this intentional?
Yeah. That is intentional.
I updated the code and removed walk function from loop body so walk function is not getting called any where now so doesn't matted if stand function is called within walk function as well.

bos1714

Great. So now you are only calling the stand() function every 5 seconds or so. Is the behavior you observed earlier still occurring?
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

Great. So now you are only calling the stand() function every 5 seconds or so. Is the behavior you observed earlier still occurring?
Yes. Well, thanks for trying.

bos1714

Did you try to add the write() before attach() like I suggested? Does this help at all?

Try replacing stand() with walk() in the loop() portion (also try with and without stand() in your walk() function)
Time line? Time isn't made out of lines. It is made out of circles. That is why clocks are round.

Ahmer

Did you try to add the write() before attach() like I suggested? Does this help at all?

Try replacing stand() with walk() in the loop() portion (also try with and without stand() in your walk() function)
What's the point of adding write before attaach function? Shouldn't it be like write after attach? Means if the servo isn't initialized, what's the point of writing to it?

Go Up