Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Motors.cpp #3018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

cedricbellec
Copy link

changed test on direction from if(direction>0) to if(direction<0) to make it right !
also recomputing diff and stopping if < 1
work great for my Arduino Robot

changed test on direction from if(direction>0) to if(direction<0) to make it right !
also recomputing diff and stopping if < 1
work great for my Arduino Robot
@ffissore ffissore mentioned this pull request Apr 22, 2015
@facchinm
Copy link
Member

@ArduinoBot build this please

@facchinm facchinm self-assigned this Apr 23, 2015
@X-Y
Copy link
Contributor

X-Y commented Apr 25, 2015

Hi Cedos,
Probably you don't need to measure and calculate the diff twice in every loop? You can do it before moving the motors(after line 31)

@cedricbellec
Copy link
Author

Hello, I tried without recomputing the diff but it wasn’t enough accurate when turning, I will try again and test if it works well with your suggestion.
Best regards
Cédric

Le 25 avr. 2015 à 18:09, X-Y <notifications@github.com mailto:notifications@github.com> a écrit :

Hi Cedos,
Probably you don't need to measure and calculate the diff twice in every loop? You can do it before moving the motors(after line 31)


Reply to this email directly or view it on GitHub #3018 (comment).

@X-Y
Copy link
Contributor

X-Y commented Apr 25, 2015

Would something like this work?

    while(1){
        int currentAngle=compassRead();
        int diff=target-currentAngle;
                if(abs(diff)<1){
            motorsStop();
            return;
        }
        direction=180-(diff+360)%360;
        if(direction<0){
            motorsWrite(speed,-speed);//right
            delay(10);
        }else{
            motorsWrite(-speed,speed);//left
            delay(10);
        }
        }

@cedricbellec
Copy link
Author

Hi again, I tried your suggestion and it works , but it far less accurate , tried this code :
void RobotControl::pointTo(int angle){
int target=angle;
uint8_t speed=80;
target=target%360;
if(target<0){
target+=360;
}
int direction=angle;
while(1){
int currentAngle=compassRead();
int diff=target-currentAngle;
if(abs(diff)<2){
motorsStop();
return;
}
direction=180-(diff+360)%360;
if(direction<0){
motorsWrite(speed,-speed);//right
delay(10);
}else{
motorsWrite(-speed,speed);//left
delay(10);
}
//if(diff<-180)
// diff += 360;
//else if(diff> 180)
// diff -= 360;
//direction=-diff;

    //currentAngle=compassRead();
    //diff=target-currentAngle;

    /*if(abs(diff)<1){
        motorsStop();
        return;
        }*/

}

}

Le 25 avr. 2015 à 18:15, Cédric Bellec cedric.bellec@hotmail.com a écrit :

Hello, I tried without recomputing the diff but it wasn’t enough accurate when turning, I will try again and test if it works well with your suggestion.
Best regards
Cédric

Le 25 avr. 2015 à 18:09, X-Y <notifications@github.com mailto:notifications@github.com> a écrit :

Hi Cedos,
Probably you don't need to measure and calculate the diff twice in every loop? You can do it before moving the motors(after line 31)


Reply to this email directly or view it on GitHub #3018 (comment).

@cedricbellec
Copy link
Author

I agree with you it looks like it would be working but the fact is that it works less accurately, with my code it turns perfectly well at right angle every times.

Maybe you can do testing on your side with both versions ?

I use the robot logo example.

Regards
Cédric

Envoyé de mon iPhone

Le 25 avr. 2015 à 18:21, X-Y notifications@github.com a écrit :

Would something like this work?

while(1){
    int currentAngle=compassRead();
    int diff=target-currentAngle;
            if(abs(diff)<1){
        motorsStop();
        return;
    }
    direction=180-(diff+360)%360;
    if(direction<0){
        motorsWrite(speed,-speed);//right
        delay(10);
    }else{
        motorsWrite(-speed,speed);//left
        delay(10);
    }
    }


Reply to this email directly or view it on GitHub.

@X-Y
Copy link
Contributor

X-Y commented Apr 25, 2015

I don't have a robot by hand at the moment, will do some tests Monday when I get back to my work place

@cmaglie cmaglie added Board: Arduino Robot Applies only to the Arduino Robot feature request A request to make an enhancement (not a bug fix) labels May 6, 2015
@facchinm
Copy link
Member

Hi @X-Y, did you manage to test the fix on real hardware? Did it behave correctly?

@cedricbellec
Copy link
Author

Hello Martino, yes I’ve tested it on real hardware and it behave correctly.

Best regards,

Cédric

De : Martino Facchin [mailto:notifications@github.com]
Envoyé : lundi 18 mai 2015 09:33
À : arduino/Arduino
Cc : Cedos14
Objet : Re: [Arduino] Update Motors.cpp (#3018)

Hi @X-Y https://github.com/X-Y , did you manage to test the fix on real hardware? Did it behave correctly?


Reply to this email directly or view it on GitHub #3018 (comment) . https://github.com/notifications/beacon/ACpYkpgHh5he4-R289mf6u9cLwErB-_Qks5oKY1HgaJpZM4EGIkV.gif

@facchinm
Copy link
Member

@Cedos14 I'm sure it works in your setup but I need at least one more feedback before merging 😏

@cedricbellec
Copy link
Author

I understand very well your opinion and I would do the same :)

De : Martino Facchin [mailto:notifications@github.com]
Envoyé : lundi 18 mai 2015 14:31
À : arduino/Arduino
Cc : Cedos14
Objet : Re: [Arduino] Update Motors.cpp (#3018)

https://github.com/Cedos14 @Cedos14 I'm sure it works in your setup but I need at least one more feedback before merging https://assets-cdn.github.com/images/icons/emoji/unicode/1f60f.png


Reply to this email directly or view it on GitHub #3018 (comment) . https://github.com/notifications/beacon/ACpYkt6tpkBHeeM0YR6gJUWk1PFXteWsks5oKdMcgaJpZM4EGIkV.gif

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Robot Applies only to the Arduino Robot feature request A request to make an enhancement (not a bug fix)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants