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

New Programmer: Need help please!
http://robotc.net/forums/viewtopic.php?f=11&t=5605
Page 1 of 1

Author:  Harmee [ Tue Mar 12, 2013 11:09 am ]
Post subject:  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!

Author:  Coder A [ Wed Mar 13, 2013 7:43 pm ]
Post subject:  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!

Author:  Harmee [ Thu Mar 14, 2013 8:28 am ]
Post subject:  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?

Author:  Harmee [ Thu Mar 14, 2013 10:09 am ]
Post subject:  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);



}



}
}

Author:  Harmee [ Thu Mar 14, 2013 10:42 am ]
Post subject:  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.

Author:  Coder A [ Fri Mar 15, 2013 9:48 am ]
Post subject:  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?

Author:  Harmee [ Fri Mar 15, 2013 10:02 am ]
Post subject:  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.

Author:  Harmee [ Fri Mar 15, 2013 3:15 pm ]
Post subject:  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.

Author:  Coder A [ Fri Mar 15, 2013 6:43 pm ]
Post subject:  Re: New Programmer: Need help please!

Could you put your code in the code tags( [ code] [ /code] with no spaces)?

Author:  Harmee [ Fri Mar 15, 2013 9:44 pm ]
Post subject:  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:

Author:  Coder A [ Sun Mar 17, 2013 9:26 am ]
Post subject:  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.

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