Light Tracking Robot Help

Now that my teams are finished with skyrise, I was starting to play with and figure out the advanced sensors. One such sensor is the light sensor. I was programming the robot the robot to look for a light and then move towards it. The servo does as instructed but all the robot does is go in circles. Can anybody help? I saw a similar code online that said it would work.

#include "Main.h"

void OperatorControl ( unsigned long ulTime )
      int rightlight; 
      int leftlight; 

      while ( 1==1 )
            SetServo ( 4 , 127 ) ;
            Wait ( 1000 ) ;
            leftlight = GetAnalogInput ( 1 ) ;
            SetServo ( 4 , 0 ) ;
            Wait ( 350 ) ;
            rightlight = GetAnalogInput ( 1 ) ;
            if ( leftlight < rightlight  )
                  SetMotor ( 3 , 0 ) ;
                  SetMotor ( 2 , 0 ) ;
                  SetMotor ( 3 , 127 ) ;
                  SetMotor ( 2 , 127 ) ;
            Wait ( 200 ) ;
            SetMotor ( 3 , -127 ) ;
            SetMotor ( 2 , -127 ) ;
            Wait ( 500 ) ;
            SetMotor ( 3 , 0 ) ;
            SetMotor ( 2 , 0 ) ;
            Wait ( 500 ) ;

Thanks for any help, Lemoore Middle College HS 6419

What do the different motors do?

Is Servo 4 a drive chassis motor or some sort of sensor positioning motor or…?

Is your left light sensor and right light sensor supposed to have their light values read from the same analog input? It looks to me like they might be reading light from the same direction (if motor 4 is some kind of sensor positioning device EDIT: sorry, on second thought, maybe this is how the SetServo command works. Probably I should keep my mouth shut since I was thinking this was RobotC. ).

Maybe a photo would help.

Are you using the light sensor or the line follower? They act a bit differently.

Line follower

Light Sensor

The servo is what moves the light sensor around a shaft. The left and right light sensors are the points the servo is pointed. I am using the “light sensor.” I am using easyC, we are currently ordering robotC.

I think I found the problem, I believe I have the sensor in a digital port. I’ll try switching it and see if it works. I’ll also post a picture ASAP.

This is our tester bot. The line trackers in the front are not being used at this point, they are for a later test. The light sensor is plugged into analog port 1.

Did you get it working or does it still move in circles? I’ve never used the light sensor but I’m guessing you need to adjust some sort of detection threshold somewhere and/or perform your tests in a fairly dark room, otherwise it will trigger on all sorts of light sources or reflective objects in the room.

As-is, it does not appear to me to have any kind of directional discrimination. In other words, the sensor is just a flat CdS cell that can accept light from a very wide angle. Would it help to put a tube over the sensor, perhaps a paper tube whose insides have been painted with a matte (non-shiny) black?

Ah yes, in a firefighting robot, someone did exactly this a few years ago (90C Cyclops I believe). They took an old 35mm film tube (we may have to explain those old relics) and cut a sliver on the end there to let in minimal light. This made it much more directional to know where the candle was in the room.

It does go in circles with the code that I posted so that may be the problem, though would adding a film tube to a competition robot be illegal because it may be considered a functional decoration that is not an official VEX part or the equivalent of??

I’m not an official, but a film tube would almost certainly be illegal. However, the rules would not prevent you from making the equivalent tube from some C-channel, black foam, black spacers, shaft collars, or whatever else you can find to fashion a tube-like shape. You are also allowed to use a certain amount of sheet plastic to cut into any shape you want.

Maybe first fix the circle movement then move on. You will need if ( leftlight < rightlight ) … else if ( leftlight > rightlight ) else …

The legality of parts is only when playing an official Vex game. If you are doing this for another competition like fire fighting, then you can use whatever you want.

Here is a picture of a firefighting apparatus that blew the candle out using some vex parts but obviously not others.