|
Page 1 of 1
|
[ 3 posts ] |
|
High school student needs help with coding!
Author |
Message |
bmabma30
Rookie
Joined: Fri Nov 07, 2014 10:25 am Posts: 1
|
 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);
}
}
|
Fri Nov 07, 2014 10:29 am |
|
 |
CARBOT
Expert
Joined: Thu Dec 01, 2011 12:07 am Posts: 151
|
 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.
|
Sat Nov 08, 2014 9:56 pm |
|
 |
Kevin Selavko
Rookie
Joined: Thu May 31, 2012 4:06 pm Posts: 25 Location: Pittsburgh, Pa
|
 Re: High school student needs help with coding!
You could try something like that. Some things that could could help you out are: Task declaration Start and stop individual tasks
_________________SHARP Sarah Heinz Advanced Robotics ProgramVEX 889A and FIRST 3260 Pittsburgh Champions Aerial Assist 2014 Pittsburgh and Buckeye Finalist Ultimate Ascent 2013 Toss Up Champions and Excellence-Pittsburgh Toss Up Champions-Northwest Maryland VRC
|
Sun Nov 16, 2014 8:02 pm |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|