View unanswered posts | View active topics It is currently Fri Sep 20, 2019 8:44 pm






Reply to topic  [ 3 posts ] 
High school student needs help with coding! 
Author Message
Rookie

Joined: Fri Nov 07, 2014 10:25 am
Posts: 1
Post 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
Fri Nov 07, 2014 10:29 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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
Profile
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 25
Location: Pittsburgh, Pa
Post 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);

_________________
SHARP
Sarah Heinz Advanced Robotics Program

VEX 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.