[URGENT] RC pulses control with Microbasic

7 years 7 months ago #29527747 by marcusbarnet
I\'m using this script (with RoboRun 1.2 7/26/12):
top:

\' Read Commands that arrived on the RC pulse inputs
Throttle = getvalue(_CIP, 1)
LeftRightJoystick = getvalue(_CIP, 2)

\' Read the sensor at pin20
WallAhead = getvalue (_DI, 16)

\' Do not allow forward motion if WallAhead
if(WallAhead = 1 and Throttle > 0) then Throttle = 0

\' Apply to motors
setcommand(_G, 1, Throttle)
setcommand(_G, 2, Steering)

\' Print on the console for debugging
print(\"rWA=\",WallAhead,\" T=\",Trottle,\" S=\",Steering\")
wait(10)
goto top

in order to try to control my HDC2450 by RC pulses (Pin15 and Pin16) and to stop the forward motion when Digital Input 16 (pin20) is at 5V (In RoboRun utility, it has active level Low).
I configured my controller to work in \"mixed mode\" in order to have a tank-steering system; then I calibrated my RC transmitter pulses.

I used the \"Download to Device\" button to load the script into the controller, then I selected \"Script Auto-Start: Enable\" and I save the new configuration to the controller.

I rebooted the controller to add these new changes and I removed the USB cable from my pc.

The problem is that nothing seems to be happened since forward motion doesn\'t stop when the digital input 16 is HIGH.
The script works well if I simulate it, but it doesn\'t work on the controller.

Why this happen? What\'s wrong with my procedure?
Is there any configuration which I have to use?
Do I need to remove the \"mixed mode\"?

Please Log in or Create an account to join the conversation.

7 years 7 months ago #29527749 by cosma
Theere are errors in your script:

You capture LeftRightJoystick, and you apply Steering. Steering is always 0.

In the print, you spell Trottle while the variable is Throttle. THis will always print 0.

Always use the \"option explicit\" at the beginning of the script. This forces you to declare each variable and will prevent problems because of misspelling.

Test the script first with the PC connected. This way you can monitor the print statement in the console and verify that you get the expected values from the digital input and are computing the correct command value.

Finally, NEVER enable auto start unless you have tested a script manually first. If there is a problem in your script that causes a crash, then you will always rebooting and crashing with no easy way to recover.

Please Log in or Create an account to join the conversation.

7 years 7 months ago #29527751 by marcusbarnet
I\'m sorry for the mistake, I just copied the wrong code.

The code I was using is this:
top:

\' Read Commands that arrived on the RC pulse inputs
Throttle = getvalue(_CIP, 1)
Steering = getvalue(_CIP, 2)

\' Read the sensor at pin20
WallAhead = getvalue (_DI, 16)

\' Do not allow forward motion if WallAhead
if(WallAhead = 1 and Throttle > 0) then Throttle = 0

\' Apply to motors
setcommand(_G, 1, Throttle)
setcommand(_G, 2, Steering)

\' Print on the console for debugging
print(\"rWA=\",WallAhead,\" T=\",Throttle,\" S=\",Steering\")
wait(10)
goto top

and there is no error with the variable declaration since I always use Steering in place of LeftRightJoystick.

The problem is that the script does not work, it seems like there is no script loaded in the controller or it is by-passed since it works directly by getting the RC pulses from my transmitter.

I really can\'t understand why this don\'t work.
Does I have to use any particular procedure?

I\'m sure the digital input is 5V (HIGH) because I can see the read led in the \"run window\" when I connect it at 5V.

Please Log in or Create an account to join the conversation.

7 years 7 months ago #29527753 by cosma
To test if the script runs, keep the PC connected and check that you get the printed text that is ouput by the script.

Also, make sure that you have RS232 as the first priority in the command priority configuration. Motor commands sent by the script have the same priorty as serial.

So if you have pulse as first priority, if your radio is on, the pulses will take priority over the script.

Please Log in or Create an account to join the conversation.

7 years 7 months ago #29527755 by marcusbarnet
It works, I had to set RS232 as first priority over Pulses.

Thank you for your help and support!

Please Log in or Create an account to join the conversation.

Time to create page: 0.177 seconds