View unanswered posts | View active topics It is currently Thu Dec 25, 2014 12:45 pm






Reply to topic  [ 3 posts ] 
trouble with color sensor 
Author Message
Rookie

Joined: Wed Dec 03, 2014 1:27 am
Posts: 2
Post trouble with color sensor
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S2,     Light,          sensorLightActive)
#pragma config(Sensor, S3,     Color,          sensorCOLORFULL)
#pragma config(Sensor, S4,     Ultrasonic,     sensorSONAR)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, PIDControl)
#pragma config(Servo,  srvo_S1_C2_1,    Arm1,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void ServoDwn()
{
   servo[Arm1]=0;
}

void ServoUp()
{
   servo[Arm1]=255;
}

void mop()
{
      motor[motorD]=0;
      motor[motorE]=0;
      wait1Msec(1000);
      if ((SensorValue[Light]>30)&&(SensorValue[Light]<50))
      {
            motor[motorD]=-3;
            motor[motorE]=0;
      }
      else
      {
      motor[motorD]=0;
      motor[motorE]=-3;
   }
      wait1Msec(1000);
      motor[motorD]=0;
      motor[motorE]=0;
      wait1Msec(1000);
      ServoDwn();
      wait1Msec(2000);
      if((SensorValue[Light]>30)&&(SensorValue[Light]<50))
      {
            motor[motorD]=10;
            motor[motorE]=0;
      }
      else
      {
      motor[motorD]=0;
      motor[motorE]=10;
   }
      wait1Msec(2000);
      motor[motorD]=0;
      motor[motorE]=0;
      if ((SensorValue[Light]>30)&&(SensorValue[Light]<50))
      {
            motor[motorD]=-3;
            motor[motorE]=0;
      }
      else
      {
      motor[motorD]=0;
      motor[motorE]=-3;
   }
      wait1Msec(2000);
      if ((SensorValue[Light]>30)&&(SensorValue[Light]<50))
      {
            motor[motorD]=10;
            motor[motorE]=0;
      }
      else
      {
      motor[motorD]=0;
      motor[motorE]=10;
   }
   
      ServoUp();
}

task main()
{
   int distance_in_cm=30;
   while(true)
   {
      if (SensorValue[Ultrasonic]<distance_in_cm)
         {
         motor[motorD]=0;
         motor[motorE]=0;
      }
      else if ((SensorValue[Color]==BLUECOLOR)&&(SensorValue[Ultrasonic]>distance_in_cm))  // if color sensors detect blue color
      {
         nxtDisplayTextLine(1, " WATER FOUND !!!");   // nxt display water found after detect water
         nxtDisplayBigStringAt(20, 36, "WATER");
         nxtDisplayBigStringAt(20, 20, "FOUND");
         PlaySound(soundBeepBeep);
        mop();
      }
      else if (SensorValue[Color]==REDCOLOR)
      {
         motor[motorD]=0;
         motor[motorE]=0;
      }
      else
         {
      if ((SensorValue[Light]>30)&&(SensorValue[Light]<50))
      {
            motor[motorD]=10;
            motor[motorE]=0;
      }
      else
      {
      motor[motorD]=0;
      motor[motorE]=10;
   }
   }
}
}

I doing a mopping robot with line follower function. The robot will assume blue color as water and will start mopping if the color sensor detect blue color. However, the NXT will display "water found" even on the black line and will go on the mop() function...I really dont know what's wrong with my coding...your help would be greatly appreciated!


Wed Dec 03, 2014 1:41 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post Re: trouble with color sensor
Quote:
I doing a mopping robot with line follower function. The robot will assume blue color as water and will start mopping if the color sensor detect blue color. However, the NXT will display "water found" even on the black line and will go on the mop() function...I really dont know what's wrong with my coding...your help would be greatly appreciated!


There may be a couple of issues that you are encountering with the program. The first thing to remember is that the robot will only do what you tell it to; the first time it detects a blue color, it will immediately display "Water Found" and go to the mop function. However, there is nothing in the code that tells the robot to change its "Water Found" message when the function is done, so the text will remain on the screen for the rest of the program.

As for the robot going to the mop function early; this may be caused by how the color sensor is setup on your robot. Try running a simple program that repeatedly shows the color sensor's detected color to the NXT's LCD display, then move the robot over the different parts of your field. Check to make sure the sensor is seeing a 'Blue' value over a blue section, a 'Red' value over a red section, and a 'Black' value over a black section.

Let us know the results and we will be more than happy to assist you further.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Dec 03, 2014 10:39 am
Profile
Rookie

Joined: Wed Dec 03, 2014 1:27 am
Posts: 2
Post Re: trouble with color sensor
After i changed the location of the color sensor, the problem solved. Thanks for your answer ^^


Sat Dec 06, 2014 1:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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

Search for:
Jump to:  



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