-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Update Motors.cpp #3018
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
Conversation
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
@ArduinoBot build this please
Build successful. Please test this code using one of the following:
http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-3018-BUILD-247-linux32.tar.xz
http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-3018-BUILD-247-linux64.tar.xz
http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-3018-BUILD-247-windows.zip
http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-3018-BUILD-247-macosx.zip
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)
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).
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);
}
}
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édricLe 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).
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.
I don't have a robot by hand at the moment, will do some tests Monday when I get back to my work place
Hi @X-Y, did you manage to test the fix on real hardware? Did it behave correctly?
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
@Cedos14 I'm sure it works in your setup but I need at least one more feedback before merging 😏
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
57dcf07
to
5a68e34
Compare
CLAassistant
commented
Apr 9, 2021
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.
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