View unanswered posts | View active topics It is currently Thu Jul 24, 2014 2:26 am






Reply to topic  [ 4 posts ] 
Help with Line tracker program using Vex Clawbot with RobotC 
Author Message
Rookie

Joined: Wed Apr 30, 2014 7:15 pm
Posts: 2
Post Help with Line tracker program using Vex Clawbot with RobotC
Can someone help me with this. I think my code is almost there but its still not working

Code:

#pragma config(Sensor, in1,    leftIR,         sensorLineFollower)
#pragma config(Sensor, in2,    centerIR,       sensorLineFollower)
#pragma config(Sensor, in3,    rightIR,        sensorLineFollower)
#pragma config(Motor,  port1,           rightMotor,    tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor,  port6,           claw,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           arm,           tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          leftMotor,     tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
    int lowIR = 1500;
    int highIR = 0;



    if(SensorValue[centerIR] > highIR) {
        highIR = SensorValue[centerIR];
    } else if(SensorValue[centerIR] < lowIR) {
        lowIR = SensorValue[centerIR];
    }

    //Set threshold as the average of light and dark.
    int threshold = (lowIR + highIR) / 2;

    // Light following loop
    while(true)
    {
        // RIGHT sensor sees dark:
        if(SensorValue(rightIR) > threshold)
        {
            // counter-steer right:
            motor[leftMotor]  = 50;
            motor[rightMotor] = 0;
        }
        // CENTER sensor sees dark:
        if(SensorValue(centerIR) > threshold)
        {
            // go straight
            motor[leftMotor]  = 50;
            motor[rightMotor] = 50;
        }
        // LEFT sensor sees dark:
        if(SensorValue(leftIR) > threshold)
        {
            // counter-steer left:
            motor[leftMotor]  = 0;
            motor[rightMotor] = 50;
        }
    }
}



Wed Apr 30, 2014 7:23 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 556
Post Re: Help with Line tracker program using Vex Clawbot with Ro
What is the robot doing, and what do you want it to do instead? The code looks like it should work, but (depending on the actual high/low values at the field) the values for your threshold may be off.

_________________
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


Thu May 01, 2014 9:31 am
Profile
Rookie

Joined: Wed Apr 30, 2014 7:15 pm
Posts: 2
Post Re: Help with Line tracker program using Vex Clawbot with Ro
Right now the robot does not do anything I put down black electrical tape on my off-white carpet. The only thing I can hear is the micro-controller.


Fri May 02, 2014 4:45 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 556
Post Re: Help with Line tracker program using Vex Clawbot with Ro
You have 3 if statements that determine what to do if one of the sensors is above the threshold value:

Code:
if(SensorValue(leftIR) > threshold)


What happens, though, if one of the sensors is below or equal to the threshold value? Or, what happens if all three of them are below the threshold value?

This might be a good place to step back from the code and write out some psuedocodefor exactly what you want the robot to do, step by step, in a more generic form (behaviors).

You can find all of this information, and more, under the Fundamentals section of the VEX Cortex Video Trainer using ROBOTC.

_________________
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


Fri May 02, 2014 5:07 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.