View unanswered posts | View active topics It is currently Thu Jul 24, 2014 9:06 am






Reply to topic  [ 11 posts ] 
New Programmer: Need help please! 
Author Message
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post New Programmer: Need help please!
So in my class we had to choose from a bunch of different options (won't go into detail) but my partner and I decided to go with a 'cookie maker'/ elevator. We are using 1 motor, 1 sonar, 2 bump switches, and 3 servos. The motor will operate the elevator, the sonar will let us tell the elevator when to stop, 1 bump switch will start the program, the other will be an 'emergency' stop & start, and the 3 servos will release a 'cookie' at the top, a 'chocolate chip' in the middle and then push them both off at the bottom. My main concern is that this is going to be impossible somehow but i am hoping that someone can help me with this or just give me some direction for my coding.

On top of that the emergency stop/start has to be pressed to stop everything and then pressed again to start the program from where it was, or at least that is what my teacher wants.

*Edit*
I'm not doing this to cheat i just really need help and my teacher only started teaching this stuff this year. So any advice on how i could get some of this to work would be much appreciated!


Tue Mar 12, 2013 11:09 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: New Programmer: Need help please!
I trust that you won't cheat, but still be aware that none of us will help you until you have some test code or questions. We can not tell you what to do with much detail at this point. Could you give some specific questions?

I will try to help!

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Wed Mar 13, 2013 7:43 pm
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
I will be posting my code and some questions i have later today :) But one of the big things i don't know how to do at all is the emergency stop WITH the start. So if it is pressed everything is stopped but when it is pressed again it all starts back up from the point it stopped. Is this even possible?


Thu Mar 14, 2013 8:28 am
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
So here is what i have. *NOTE* The numbers are not actually what i want them to be, measurements are still being done. As for the code, i want the elevator to start at the top and then a servo will push for flick or something the cookie onto the platform, which will then go down to the next level where it will wait for a Chocolate Chip to be pushed onto the cookie, it will then go to the bottom where it is hit off into a bin. After all of that it will return to the top where the process will be done again into there are no cookies left.

task main()
{

while(1==1)
{


if(SensorValue(startbump) == 1 && (CookieFollower) == 10)
{
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(CookieM, 60);
wait(3);
setServo(CookieM, 0);
startMotor(elevatorM, 60);
turnLEDOff(Yellow);
turnLEDOn(Green);
untilSonarLessThan(sonar1, 6);
stopMotor(elevatorM);
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(chipServo, 60);
wait(3);
turnLEDOn(Green);
turnLEDOff(Yellow);
setServo(chipServo, 0);
startMotor(elevatorM, 60);
untilSonarLessThan(sonar1, 1);
stopMotor(elevatorM);
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(TransportS, 60);
wait(3);
setServo(TransportS, 0);
turnLEDOff(Yellow);
turnLEDOn(Green);
startMotor(elevatorM, -60);
untilSonarGreaterThan(sonar1, 10);



}



}
}


Thu Mar 14, 2013 10:09 am
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
I also tried this code (not tested)

if(SensorValue(startbump) == 1)
{
if(SensorValue(sonar1) == 10)
{
setServo(CookieM, 120);
turnLEDOn(Yellow);
wait(3);
startMotor(elevatorM, -30);
setServo(CookieM, 0);
turnLEDOff(Yellow);
turnLEDOn(Green);
}
if(SensorValue(sonar1) == 5)
{
setServo(chipServo, 120);
stopMotor(elevatorM);
turnLEDOn(Yellow);
turnLEDOff(Green);
wait(3);
setServo(chipServo, 0);
startMotor(elevatorM, -30);
turnLEDOff(Yellow);
turnLEDOn(Green);
}
if(SensorValue(sonar1) == 1)
{
setServo(TransportS, 127);
stopMotor(elevatorM);
turnLEDOn(Yellow);
turnLEDOff(Green);
wait(3);
setServo(TransportS, 0);
startMotor(elevatorM, 30);
turnLEDOff(Yellow);
turnLEDOn(Green);
untilSonarGreaterThan(sonar1, 9);

}

}
}

Whichever one is better let me know.


Thu Mar 14, 2013 10:42 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: New Programmer: Need help please!
I would say the best way to do the emergency stop is to start a new task that runs a loop until the em. button is pressed, and then hogs the cpu, with hogCPU(). Then it runs a second loop until the button is pressed again, then releasing the CPU with releaseCPU().

As for the rest of the code, tell me if this is accurate psuedo-code (fake code):
1.wait for button to be pressed.
2.push cookie into elevator.
3.go to floor 2.
4.push chip into elevator.
5.go to floor 1.
6.push cookie & chip out.
7.go to floor 3.
8.repeat steps 2 through 6 until there are no cookies left.

Are hogCPU() and releaseCPU() supported on VEX? You see, I actually do not have a VEX, I have an NXT, so I can only help with code structure, not actual commands.

Do you have any more questions?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri Mar 15, 2013 9:48 am
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
I think that the hogCPU() and releaseCPU() are supported. As for the other stuff that is the just of the program. However the two different codes i wrote weren't working. The code wouldn't recognize the sonar and would go on forever.


Fri Mar 15, 2013 10:02 am
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
Actually after i changed my sonars i had the numbers and the name of the sonar in the wrong order. The only problem with the first code is that after it is done it goes back to the top but does not stop. Everything else seemed to work.


Fri Mar 15, 2013 3:15 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: New Programmer: Need help please!
Could you put your code in the code tags( [ code] [ /code] with no spaces)?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri Mar 15, 2013 6:43 pm
Profile
Rookie

Joined: Tue Mar 12, 2013 10:54 am
Posts: 7
Post Re: New Programmer: Need help please!
Code:
task main()
{

while(1==1)
{


if(SensorValue(startbump) == 1 && (CookieFollower) == 10)
{
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(CookieM, 60);
wait(3);
setServo(CookieM, 0);
startMotor(elevatorM, 60);
turnLEDOff(Yellow);
turnLEDOn(Green);
untilSonarLessThan(6, sonar1);
stopMotor(elevatorM);
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(chipServo, 60);
wait(3);
turnLEDOn(Green);
turnLEDOff(Yellow);
setServo(chipServo, 0);
startMotor(elevatorM, 60);
untilSonarLessThan(1, sonar1);
stopMotor(elevatorM);
turnLEDOff(Green);
turnLEDOn(Yellow);
setServo(TransportS, 60);
wait(3);
setServo(TransportS, 0);
turnLEDOff(Yellow);
turnLEDOn(Green);
startMotor(elevatorM, -60);
untilSonarGreaterThan(10, sonar1);



}



}
}



There you go. So like i said it all generally works up to the very end where it starts to go back up BUT it doesn't stop going up.
thanks again for helping :biggrin:


Fri Mar 15, 2013 9:44 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: New Programmer: Need help please!
I think the problem is that the elevator motor is not stopped after the untilsonargreaterthan command. Stop it as the line following the USGT command, and everything should work fine.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Sun Mar 17, 2013 9:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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

Search for:
Jump to:  



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