User Control AND a Program

So I have a robot set up with a custom user control. What i need is to keep the same custom user control but also add in a program that will drive the bot through a maze.

the set up i am using for the custom control involves a while loop while (1==1) with all of the control inside it

how should i go about using both because i need to be able to “Turn On” and “Turn Off” the maze program and switch it to the “Control” program?

The advice i want to give is hard for me to explain, but ill try…
Try putting your user control in it’s own function, and the ‘maze’ program in another function. Then, in another function that incorporates both the user control function and the maze function, like the competition templates do, make an if loop stating the conditions in which to use each function.

You need to use an if statement to to switch the maze on and off.

while(1==1)
{
if(blah)
{
maze code
}
else
{
radio control code
}
}

If you look through main() in the Line Tracker code, you’ll see something similar.

That code watches a pair of back buttons to switch between remote control and auto-line-tracker mode. That way you can drive the robot onto the line, let it do its thing, then easily stop it if/when it goes off into the weeds.

Have a look and let me know if you have any questions.

Cheers,

  • Dean

could i make it so that if a jumper clip is inserted the bot will go to the maze program and if i take it out then the bot uses normal human operator controls? if so how do you create a function to do this? i have used the help thingy in easy c to try to make functions but i have never been successful.

Thanks

You don’t even need to use 2 back buttons, you can just use 1 as a toggle.

Another option (which I think is probably a terrible idea, actually) is that when using RobotC (I’m sure the others have it to) you can differentiate between when the remote control is off or on.

In theory (and again, I think this is a horrible idea), you could use that as a way of going between controlled and autonomous mode. I personally use this feature as a remote kill switch, if the remote isn’t on the autonomous code just doesn’t run. But it could be useful if you absolutely needed all the buttons.

But don’t blame me when your robot goes crazy, eats your cat, throws napalm on your collection of expensive shoes and dates your mom. I told you not to do it.

that sounds cool but I’m using easy c please see my above post

The Line Tracker code I pointed you to is in EasyC.

  • Dean

i can’t view it cause i don’t have easy c on this computer.

True. However, using 2 buttons has at least these advantages:
[LIST=1]
*]No guessing about which mode you just entered. One button per mode makes it clear. Toggling requires you to know where you started from.
*]No need to debounce. If you use one button, you have to watch for the button to be released before you watch for it to be pressed again. Using two buttons eliminates the need for this extra code.
[/LIST]
Obviously, if you need the buttons for other purposes, then one button is the way to go. In my case, I didn’t need the buttons for anything else, so I went with 2.

Cheers,

  • Dean

i am hoping to use a jumper clip as the function

That is as simple as inserting getdigitalinput(your port) in the code i gave you above.

so if i understand what you said then were you had blah written before i would now put getdigitalinputport1? wouldn’t i still have to specify that the jumper clip is in or if it is out?

Yes accept you would need a digital input because port 1 is analog.So, If(GetDigitalInput(5))

so the way you just put that is there is a jumper in port 5 then the bot will run maze program without a jumper it will run user control program.

the part i don’t fully understand is when you say If(GetDigitalInput(5)) does this mean if the microcontroller receives input from port 5 then… or is it an instruction to get input in which case more programming would be needed?

also you put it once as

getdigitalinput

and once as

GetDigitalInput

Does it matter which i use?

Well your final code would look something like this:

while(1==1)
{
if(GetDigitalInput(5))
{
Your Maze Code
}
else
{
RC Control Code
}
}
(use this one)
if(GetDigitalInput(5)) means ‘if there is a jumper on port 5 do this’
Im sorry for being unclear in my last posts

so you do use caps for the GetDigitalInput(5) part.

yes you do use caps

muchos gracias you have been a big help

I am trying to do this on a dig. output, but out of every loop/if/then/while/for combination I’ve tried, I still can’t get it. I will keep trying, but any help on how to do this would be great.

(by the way, the code is for Nelson III)