ROBOTC.net forums
http://www.robotc.net/forums/

High school student needs help with coding!
http://www.robotc.net/forums/viewtopic.php?f=11&t=9762
Page 1 of 1

Author:  bmabma30 [ Fri Nov 07, 2014 10:29 am ]
Post subject:  High school student needs help with coding!

I am coding an automated guided vehicle. The machine needs to start with the press of a button, and move back and forth until an emergency stop is pressed. I have the code for the loop to make it continue on the path i want, but i cannot figure out how to code in an emergency stop. Any suggestions appreciated. I can only get to where i can make it stop when the loop starts over. but it needs to be able to be stopped at any point in the loop. The code I have so far:

task main()
{wait(1);
untilBump(dgtl1, 5);
startMotor(port1,55);
startMotor(port10,55);

while(SensorValue(bumpswitch)==0)
{
if(SensorValue(bumpswitch)==1)
{
stopMotor(port1);
stopMotor(port10);
}
untilBump(dgtl2, 5);
stopMotor(port1);
stopMotor(port10);
wait(1);
startMotor(port1,-55);
startMotor(port10,-55);
untilBump(dgtl3,5);
stopMotor(port1);
stopMotor(port10);
wait(1);
startMotor(port1,55);
startMotor(port10,55);

}

}

Attachments:
File comment: robotc file
car code2.c [1.22 KiB]
Downloaded 358 times

Author:  CARBOT [ Sat Nov 08, 2014 9:56 pm ]
Post subject:  Re: High school student needs help with coding!

In order to do something at any time you need to be continuously scanning for it and be able to act on it. To make this happen your code needs to use commands that do something and move on without waiting. You must avoid commands that tie up the processor such as ‘wait’ or ‘until…’. By having your main loop execute and keep moving, the ability to add things like a blinking LED or estop button become quite easy.

My recommendation would be to use the switch/case statement to increment through the motions in your assignment. In lieu of a wait, each step would check a timer to see if it should move on. The until statements would be replaced by not incrementing until the press and release was detected.

This will make your code longer but not burn CPU time by doing nothing during the wait and until… statements. Please try this and post the result. We could help with that code, unlike your existing code.

Author:  Kevin Selavko [ Sun Nov 16, 2014 8:02 pm ]
Post subject:  Re: High school student needs help with coding!

Code:
Estop task
{
 repeat forever
 if button
 stop Drive task
}
Drive task
{
*your drive code*
}
Start Drive Task and Estop task


You could try something like that.
Some things that could could help you out are:

Task declaration
Code:
task Drive()
{
//Code
}


Start and stop individual tasks
Code:
startTask(task);
stopTask(task);

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/