View unanswered posts | View active topics It is currently Thu Aug 21, 2014 10:02 am






Reply to topic  [ 4 posts ] 
Infrared sensor how to program? 
Author Message
Rookie

Joined: Thu Dec 09, 2010 8:40 pm
Posts: 1
Post Infrared sensor how to program?
So, I currently have the robot programmed run motors and servos, but I have no idea how to program sensors. I want to program an infrared seeker sensor, but I have no idea where to start. I've searched for it, but most of all I found is just people who have had problems with accuracy or needing some driver or something. How do I start programming the sensor?


Thu Dec 09, 2010 8:44 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Infrared sensor how to program?
Did you see the code posted on this thread?
viewtopic.php?f=52&t=2780
This code gives you a function that returns a relatively accurate heading if you point it sideway. If you use this function as the input to a PID controller, you will have a robot that will turn towards the IR beacon. For example, assuming zone 2 is the dead ahead zone, a simplified version of the code looks something like this:
Code:
void IRDrive(int drivePower)
{
    int turnPower = (int)(Kp*(IRGetACDir(irSeeker) - 2.0));
    if (turnPower > 100)
    {
        turnPower = 100;
    }
    else if (turnPower < -100)
    {
        turnPower = -100;
    }
    int leftPower = drivePower + turnPower;
    int rightPower = drivePower - turnPower;
    if (leftPower > 100)
    {
        leftPower = 100;
    }
    else if (leftPower < -100)
    {
        leftPower = -100;
    }
    if (rightPower > 100)
    {
        rightPower = 100;
    }
    else if (rightPower < -100)
    {
        rightPower - -100;
    }
    motor[leftMotor] = leftPower;
    motor[rightMotor] = rightPower;
}


Fri Dec 10, 2010 5:26 am
Profile
Rookie

Joined: Fri Oct 21, 2011 11:14 pm
Posts: 9
Post Re: Infrared sensor how to program?
What is the meaning of Kp?

Thanks!


Sat Nov 26, 2011 4:23 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Infrared sensor how to program?
hongyeus wrote:
What is the meaning of Kp?

Kp is the Proportional Constant in PID control. If you are not familiar with PID control, you can read the following article.
http://en.wikipedia.org/wiki/PID_control
Basically, it said the output power of the motor should be proportional to how far you are from your target. If you are very far from your target, PID control will try to drive with maximum power. If your are very close to your target, PID control will slow down so you don't overshoot. Kp is a constant you must tune so that it's value is big enough to get the robot to target as fast as possible and yet not overshooting. To tune this value, you can try something big first. If it overshoots and oscillates when reaching target, tune this value smaller until it no longer oscillates. PID control involves other constants too, but if you are not familiar with it, you can just use Kp and ignore the other constants.
In the IRDrive function, Kp is to control how quickly the robot turns towards the IR. The bigger Kp the faster it will turn towards the IR but risking overshooting (turn too much). The smaller Kp the slower it will turn to the IR but more accurate. You can try an initial value of 20 to 25 and see how it goes and tune it from there.


Sat Nov 26, 2011 10:31 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.