View unanswered posts | View active topics It is currently Sun Jul 22, 2018 8:36 am






Reply to topic  [ 4 posts ] 
Help with firefly bot 1 
Author Message
Rookie

Joined: Mon Nov 09, 2015 12:56 pm
Posts: 2
Post Help with firefly bot 1
Does anyone know how can I compare the values of the light sensor? I need to take the highest value and make the robot go to that point


Mon Nov 09, 2015 2:28 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: Help with firefly bot 1
So if you wanted to make a robot spin in place to find the angle of the largest light value you would do something like this

Code:
#pragma config(StandardModel, "SQUAREBOT - IME")
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{   //the value of currentEncoderTicks after having
    //completed an entire rotation
    int totalEncoderTicksInFullRotation=100;
    int largestLightSeen=0;
    int encoderTickOfLargestValue=0;
    int currentEncoderTicks=0;

    motor[leftMotor]=-20;
    motor[rightMotor]=20;
    while(currentEncoderTicks<=totalEncoderTicksInFullRotation){
        currentEncoderTicks = nMotorEncoder[rightMotor]-nMotorEncoder[leftMotor];
        if(SensorValue[light]>largestLightSeen){
            largestLightSeen=SensorValue[light];
            encoderTickOfLargestValue=currentEncoderTicks;
        }
       wait1Msec(50);//not hog the cpu
    }
    stopAllMotors();   
}

Right now it will not turn a full rotation because I used a "magic" number of 100 encoder ticks per full rotation. Try out a few numbers until you find out how many ticks it takes your robot to spin a full rotation. So this program will find the angle of the largest light value. Turning to that angle should be fairly straight forward.


Tue Nov 10, 2015 11:23 am
Profile
Rookie

Joined: Mon Nov 09, 2015 12:56 pm
Posts: 2
Post Re: Help with firefly bot 1
Thanks man it really works, but the problem is that when I make the robot spin to the largest value after it has completed a full rotation, he doesn't go to the exactly to the light position so i cant't go straight forward. Do you know how to fix it?


Fri Nov 13, 2015 9:50 am
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: Help with firefly bot 1
If you are having issues turning to light after finding its location I would recommend turning to the angle you believe it to be at and when you get close to the angle switch to turning to look for the value that you represents the fire. Use the encoder data to get you within something like 5 degrees of the correct angle and then use the line sensor to look for the variable
largestLightSeen

If you can't get something like that to work if you post your code I can give some pointers to get you facing the right direction. (I made a pun)


Fri Nov 20, 2015 3:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.