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.
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.
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.
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.
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.
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?
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?
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
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.