Converting sensor value to servo movement
Botdocter
Posts: 271
I am building a robot containing a Wyse Thin XP system. it uses roborealm and i have setup the serial connection to the propeller. it is working correct. i get back the values that where send by roborealm.
Now i need to convert one of that values to servo movement. or in other words, the value is the camera resolution or a point withing that width.(320px / 2 =160 to -160). That value that is changing constantly, and has to drive the servo to steer the robot.
i attached my main file. it's not working though. all i get is -160 outputted back to roborealm and the servo starts with a quick left then right and then no movement. The servo can't be turned manually. It is still holding steady at ...-160? would be pulsewidth "1300"?
Any help is apreciated!!
RRSerial.spin
Now i need to convert one of that values to servo movement. or in other words, the value is the camera resolution or a point withing that width.(320px / 2 =160 to -160). That value that is changing constantly, and has to drive the servo to steer the robot.
i attached my main file. it's not working though. all i get is -160 outputted back to roborealm and the servo starts with a quick left then right and then no movement. The servo can't be turned manually. It is still holding steady at ...-160? would be pulsewidth "1300"?
Any help is apreciated!!
RRSerial.spin
Comments
SERVO.Set(ServoCh1,Heading,50)
instead of
SERVO.SetRamp(ServoCh1,Heading,50) ?
Rich H
If i change the -160 at the bottom of the file, to for example: 162, that is what i get back. So it is not using the value but the -160???
John Abshier
i will try again anyway..
thanx
Rich H
You have the values ranging from -160 to 160 that need to correspond to servo pulses of 1,300 to 1,700 with 1,500 being the center.
If you could get by with a pulse range of 1340 to 1660 then it would be super easy;
heading := 1500 + rxVal_1
But to scale the 160 up to 200 you need to multiply it by 1.25. Or multiply it by 125 then divide by 100.
heading := 1500 + ((rxVal_1 *125) / 100)
You should be able to replace your Main loop with this;
It is of course untested...
Rich H
I want to make some comments about your code.
As your methods SerCog, Transmitter and WheelAngle do NOT contain any loop.
The commands cognew start a new cog executes the codeline ONE time and then stops the cog again.
You should get the same results if you just delete the cognew-statements
As you don't have any code below the "elses" INDENTED in the method WheelAngle
you can simply delete the elses
If you meant that the second-ifcondition should only be executed if the first is not true
You would have to indent them.
The following codelines compile but are different from the ones above and below
I think you wanted to code
IF rxVal_1 := 140
sets rxVal_1 to value 140
and the if-condition will be true as every value <> 0 is true
for the codelines
I guess you mean value-range -20 to -40
rxVal_1 > -20 is TRUE for -19, -18, -17, -16 etc. etc.
I guess you wanted
rxVal_1 < -20
which is true for -21, -22, -23, etc. etc.
instead of adding a lot of if-conditions you can use
a case-statement
from the bugs you made I guess you are pretty new to programming.
My recommendation is to add only 1 to 5 lines of code and then TESTING the code to check if it really does what you expected.
For the testing you should hold anything constant but teh one thing you want to test
example
to test what does the codelines
you should extract the codelines to a small test-program that only contains
with this testing code it will be easy to check if your code works as expected and you will be pointed straight forward to a bug
if there is a bug.
You may think uhh so many test-programms?!? This takes too long.
OK it is up to you to do it the fast (but in the long run slowest) way to quickly put together all the code and then start testing with guessing around
is the bug here ore there?
Very old programmers -wisdom: a program does ALWAYS what you have programmed. The only thing is sometime you don't know what you really programmed
because you thought the program should do this but in fact the program does something different. But still EXACTLY what you have programmed.
best regards
Stefan
I keep falling into this trap Myself... Comments are Your best hope >>> ' <<< Document often, Walk Yourself Thru all Code.
and F9 is your new best friend...
What will happen if the value is 20? Try this instead;
And...
will not work, should be;
Still, I think that this is a much better approach than all those IF statements;
Rich H
here is a new RRserial_1.spin
changed: pst
Servo32.spin
no serial connections
i make a short test (no servo connected) it's run
regards nomad