View unanswered posts | View active topics It is currently Sat Oct 25, 2014 10:34 am






Reply to topic  [ 8 posts ] 
Problems with my EV3 colour sensor 
Author Message
Rookie

Joined: Tue Jul 29, 2014 3:07 pm
Posts: 6
Post Problems with my EV3 colour sensor
I have to detect some colours with my EV3 colour sensor and it doesn't work as it is supposed. When I try the code debugging, it works fine, but when I try the code on the robot, without debugging it doesn't work. Is it one of the known issues to correct? And, will it work if I change put the NXT colour sensor instead of the EV3 colour sensor? (To change it I have to dismount a lot of things of my robot).
Otherwise, what am I doing wrong?

This is a simple code that works debugging but not when I run it on the robot
Code:
task main(){
setSensorMode(color, 2); //color is the name that I have given to the sensor
if (SensorValue(color)==6) //now it is detecting white
    base_180(); //it moves a motor 180 degrees
else
    base_90_AH();    //it moves a motor 90 degrees.
}


In this case, detecting always the same thing, if it is debugging, it moves a motor 180 degrees. Running it without debugging, does the 'else' case, it moves the motor just 90 degrees


Tue Jul 29, 2014 3:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Problems with my EV3 colour sensor
You need some kind of while loop in there so that it doesn't run straight through.

Code:
task main(){
  setSensorMode(color, 2); //color is the name that I have given to the sensor
  while (true)
  {
    if (SensorValue[color]==6) //now it is detecting white
      base_180(); //it moves a motor 180 degrees
    else
      base_90_AH();    //it moves a motor 90 degrees.
  }
}


= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jul 30, 2014 1:19 am
Profile WWW
Rookie

Joined: Tue Jul 29, 2014 3:07 pm
Posts: 6
Post Re: Problems with my EV3 colour sensor
Okay, thanks.
However, I have realised that it works as you have told me with that while loo, but that is not exactly what I want. In fact, I am trying to make a Rubik's cube solver, and I want to save the colors of the cube in an array. So, I don't understand why I need that while loop, because in the function "base_180()" I am using the "waituntilmotorstops" function, so it should do that and then continue with the next statement when the motor has stopped, in this case, however, nothing else.

Anyway, if I save the value of the colors of the cube in an array, will it save the values without any while loop or something like that?


Wed Jul 30, 2014 8:39 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Problems with my EV3 colour sensor
How do you propose to go through the array to assign values to it? You will need a loop for that, no?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Aug 01, 2014 4:40 am
Profile WWW
Rookie

Joined: Tue Jul 29, 2014 3:07 pm
Posts: 6
Post Re: Problems with my EV3 colour sensor
Yes, but the problem here is that when I try a program debugging, step by step, it does one thing, but when I try the program from the robot, or clicking on the "start" button on the PC instead of the "step" one, it does another thing.
I copy you the program here:
Code:

void base_90_H(){ //moves the motor 90 degrees to one side
   moveMotorTarget(base, 630, -100); //I am using several gears
   waitUntilMotorStop(base);
}

void base_90_AH(){ //moves the motor 90 degrees to the other side
   moveMotorTarget(base, 630, -100); //I am using several gears
   waitUntilMotorStop(base);
}

task main(){
   int value;
   setSensorMode(color, 2);
   value = SensorValue(color);
   if (value==6){
      base_90_H();
   }else{
      base_90_AH();
   }
}



I can't understand why this doesn't work.


And finally, I have just found something really strange.
If using the previous functions I put the code in a while (true) loop and the sensor is always detecting the same colour, the first time or the two first times it does what's inside the "else" statement and the next ones what is inside the "if" one.
I don't know if the programme is wrong or what.

Code:
task main(){
   int value;
   setSensorMode(color, 2);
   value = SensorValue(color);
   value = SensorValue(color);
   value = SensorValue(color);
   value = SensorValue(color);
   value = SensorValue(color);
   if (value==6){
      base_90_H();
   }else{
      base_90_AH();
   }
}


I have also tried doing this, but it doesn't work neither :(


Fri Aug 01, 2014 11:58 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Problems with my EV3 colour sensor
All 5 SensorValue[] statements shouldn't take more than a few milliseconds to complete. Is that what you want?

In your first program, how often do you expect the sensor to actually be read?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Aug 01, 2014 12:09 pm
Profile WWW
Rookie

Joined: Tue Jul 29, 2014 3:07 pm
Posts: 6
Post Re: Problems with my EV3 colour sensor
Now I feel a bit stupid... :S
It was that. With a small delay now it works as it is supposed... I thought I had gone mad haha
THANK YOU VERY MUCH! :D :D :D


Fri Aug 01, 2014 12:45 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Problems with my EV3 colour sensor
You may still be mad, but at least your sensor is working!

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Aug 01, 2014 2:24 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: hexafraction 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.