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

hi technic color sensor help. plz save us oh mighty internet
http://www.robotc.net/forums/viewtopic.php?f=15&t=3802
Page 1 of 1

Author:  teddy268 [ Wed Nov 30, 2011 11:44 am ]
Post subject:  hi technic color sensor help. plz save us oh mighty internet

i have a class of 5 others in my robotics 2 class. :) 8) :breakcomputer: :poke: :twisted:<-(me) :lol: we love this class the best out of our day. currently we are working on a color sensing robot that can sort colored balls(highly origanal)
we have all apparently biult robotic arms that will pick the balls up.
(yes i now realize that there are mush simpler ways of doing this)
i have figured out how to tell the color sensor what color is what, and how to display it onto the screen. the only problem is how to tell the robot to do a order of comands after it knows what color it has in it powerful grasp. right now it is trying to do them all at once and some times it wont stop. i have been stuck in the same place for about a week and the teacher is no real help it seems that i know more than he does, anyway before i lose my already dwindling sanity plz help us. i only have blue right now.

CODE__________________________________________________________
#pragma config(Sensor, S1, colorPort, sensorI2CHiTechnicColor)
#pragma config(Motor, motorA, claw, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, vertical, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, base, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
string sColor;

while (true) {
switch (SensorValue[colorPort])
{
case 2: sColor = "Blue";
motor[motorA]=-10; //claw close
wait1Msec(200);
motor[motorB]=5; //arm rise
wait1Msec(100);
motor[motorC]=10; //base turn right
wait1Msec(4000);
motor[motorB]=-10; //arm goes down
wait1Msec(2000);
motor[motorA]=10; //claw open
wait1Msec(255);
motor[motorB]=10;//arm goes Up
wait1Msec(352);
motor[motorC]=30; //base turns
wait1Msec(500);
motor[motorB]=-10; //arm goes down
wait1Msec(500);
motor[motorC]=50; //base turns
wait1Msec(800);


break;
case 4: sColor = "Green"; break;
case 6: sColor = "Yellow"; break;
case 8: sColor = "Red"; break;
default: sColor = "(>^^)>@<(^^<)"; break;
}
nxtDisplayCenteredTextLine(2, sColor);
wait1Msec(50000);
}
}
---------------------------------------------------------------------------
sesion terminated---- :breakcomputer:

Author:  magicode [ Wed Nov 30, 2011 11:51 am ]
Post subject:  Re: color sensor help!!! plz save my sanity

So what is your question? What are you having trouble with?

Author:  teddy268 [ Wed Nov 30, 2011 2:56 pm ]
Post subject:  Re: color sensor help!!! plz save my sanity

magicode wrote:
So what is your question? What are you having trouble with?

when ever i put the blue ball on to the loading track the color sensor knows that it is blue but the motors all try to go at the same time. so i need it to do the comands in order.

Author:  magicode [ Wed Nov 30, 2011 4:39 pm ]
Post subject:  Re: hi technic color sensor help. plz save us oh mighty inte

Well, for one thing, you never tell your motors to stop. Here is the part of your code that makes the motors move:
Code:
motor[motorA]=-10; //claw close
wait1Msec(200);
motor[motorB]=5; //arm rise
wait1Msec(100);
motor[motorC]=10; //base turn right
wait1Msec(4000);
motor[motorB]=-10; //arm goes down
wait1Msec(2000);
motor[motorA]=10; //claw open
wait1Msec(255);
motor[motorB]=10;//arm goes Up
wait1Msec(352);
motor[motorC]=30; //base turns
wait1Msec(500);
motor[motorB]=-10; //arm goes down
wait1Msec(500);
motor[motorC]=50; //base turns
wait1Msec(800);

(You can use code tags to preserve your formatting, and it makes the code nice and easy to read)
You tell motor A to move, and keep moving for 200 milliseconds, but you never say 'motor[motorA]= 0;" to stop it from moving. So all those commands are executing one after the other as I assume you intend, but they "overlap" because you never stop the motors.

Author:  teddy268 [ Thu Dec 01, 2011 11:27 am ]
Post subject:  Re: hi technic color sensor help. plz save us oh mighty inte

asumeing that this is what you intended for us to do.
---------------------------------------------------------------------------
#pragma config(Sensor, S1, colorPort, sensorI2CHiTechnicColor)
#pragma config(Motor, motorA, claw, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, vertical, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, base, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
string sColor;

while (true) {
switch (SensorValue[colorPort])
{
case 2: sColor = "Blue";
motor[motorA]=-10; //claw close
wait1Msec(800);
motor[motorA]=0;
wait1Msec(500);
motor[motorB]=10;//arm rise
wait1Msec(1200);
motor[motorB]=0;
wait1Msec(500);
motor[motorC]=10; //base turn right
wait1Msec(4000);
motor[motorC]=0;
wait1Msec(500);
motor[motorB]=-10; //arm goes down
wait1Msec(2000);
motor[motorC]=0;
wait1Msec(500);
motor[motorA]=10; //claw open
wait1Msec(255);
motor[motorA]=0;
wait1Msec(500);
motor[motorB]=10;//arm goes Up
wait1Msec(352);
motor[motorB]=0;
wait1Msec(500);
motor[motorC]=30; //base turns
wait1Msec(500);
motor[motorC]=0;
wait1Msec(500);
motor[motorB]=-10; //arm goes down
wait1Msec(500);
motor[motorB]=0;
wait1Msec(500);
motor[motorC]=50; //base turns
wait1Msec(800);
motor[motorC]=0;
wait1Msec(500);


break;
case 4: sColor = "Green"; break;
case 6: sColor = "Yellow"; break;
case 8: sColor = "Red"; break;
default: sColor = "fother mucker"; break;
}
nxtDisplayCenteredTextLine(2, sColor);
wait1Msec(500);
}
}
===========================================================
the motors are now not over lapping but it seems that do them out of order or that if i say motor[motorB]=10; wait1Msec(800) it might do motor C.
all of the motors and sensors are set up correctly in the debuger window. the only thing that i can think of is ethier i am missing a part of this type of program code. or i am just not givivg it the time that it needs. although since it seems to be jumping lines im just asking if there is any major problem that you can see that is sticking out oh mighty gu ru.

Author:  magicode [ Thu Dec 01, 2011 12:58 pm ]
Post subject:  Re: hi technic color sensor help. plz save us oh mighty inte

According to your code, this is what should be happening now:

Motor A moves at -10 power for 0.8 seconds and stops
Nothing happens for 0.5 seconds
Motor B moves at 10 power for 1.2 seconds and stops
Nothing happens for 0.5 seconds
Motor C moves at 10 power for 4 seconds and stops
Nothing happens for 0.5 seconds
Motor B moves at -10 power...and here is where you might have your problem.
You never tell motor B to stop. You tell motor C to stop instead, but it's already stopped. I assume that this is a typo. Saying what your code does out loud like this helps.

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