
Andy Roid
USA
Asked
— Edited
I have been messing with this for a while and can't make progress. I want to track forward on a set compass heading. If there is a variation from the heading I want to make a correction turn back toward the heading. I have made the compass to read with a +/- 5 degree tolerance. For setup I am using a deviation of 30 degrees, but will narrow it to 10 degrees once it is working.
$compass_setting = 150
$compass_setting2 = $compass_setting + 30
$compass_setting3 = $compass_setting - 30
:loop
if ($CompassHeading = $compass_setting)
Forward()
endif
if ($CompassHeading = $compass_setting3)
Left()
endif
Goto(:loop)
I have tried a number of variations but no luck.
Any ideas?
Ron
First, you say compass_setting as variables, but compass_heading as another.
Second, you have capitals where you shouldn't.
Third, you dont need individual ifs for each variable. Use elseif to lump it together.
Seems like a bit of midnight coding if you ask me!
A bit of an oversight I often do myself!
Don't forget about this other thread you have going on with code examples that i provided
https://synthiam.com/Community/Questions/9909
You should also put a sleep() command in your loop to avoid flooding the channel....
And a sleep will give the robot at least some time to respond to the movement command.
Continually sending a Left() to the robot will keep reset the movement to left. it's already going left, so no point to keep sending left().
Probably a good idea to check what the current direction is before sending the command again.
Thanks, I appreciate the guidance. I will try again with the suggestions in mind. Ron
Using the above example, and answers, I got the full script working by adding the required Sleep commands Dj and Richard suggested. I am now working on getting all the test scripts in one project and running together.
Thanks for the help.
Ron
Cool! That's coming along well