View unanswered posts | View active topics It is currently Tue Feb 09, 2016 2:01 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Infrared sensor how to program?
Author Message
Rookie

Joined: Thu Dec 09, 2010 8:40 pm
Posts: 1
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

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

Thanks!

Sat Nov 26, 2011 4:23 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    2014 Robotics Academy Summer of Learning    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge