Author |
Message |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 NXT Light Sensor IR
Does the NXT light sensor detect IR radiation? Does it detect it well? Should my team buy a different IR detector? What kind should we buy?
|
Thu Nov 08, 2012 9:44 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
Are you using it for the FTC Ring It Up competition? If so, you need this. http://www.hitechnic.com/cgi-bin/commer ... ey=NSK1042
|
Fri Nov 09, 2012 1:13 am |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
Thank you. But when I look for how to program this with RobotC, nothing comes up. How does one program this sensor? Do you have to make custom nodes? (I hope not, my programming skills are nowhere near that level.)
|
Tue Nov 13, 2012 5:24 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
No, Xander has written a 3rd party sensor library suite that even comes with sample code. Please refer to this thread on how to download it. http://robotc.net/forums/viewtopic.php?f=1&t=5060The sample you may want to look at is the hitechnic-irseeker-v2-test1.c or hitechnic-irseeker-v2-test2.c.
|
Tue Nov 13, 2012 6:49 pm |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
Whoa. I downloaded the driver software and got it working, but when I open the sample code it is a long string of stuff that makes no sense to a simple programmer like me. Is there some way to make it just be: 'if the sensor is activated in this section, the robot turns to face the sensor' without having code that is 2 pages long? Help? Please?
|
Tue Nov 27, 2012 6:12 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
The sample code was trying to demonstrate different modes and capabilities of the IR seeker. If you just want to know which direction is the IR beacon, all you need is this single call: That's all you really need!
|
Tue Nov 27, 2012 8:55 pm |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
So, how would I use this call to make the robot go towards the IRBeacon? I pretty much just need the context the call would be used in and then I'll understand it.
|
Thu Nov 29, 2012 6:28 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
HTIRS2readACDir() returns a value between 1 to 9 showing you the direction of the IR beacon with 1 being on your far left, 5 dead ahead and 9 being on your far right. This is very similar to line following. You can apply simple Proportional PID control to do this. For example, The above code will keep driving towards the IR. Obviously, you need to determine and add code on when it should stop. Also note that zone 5 of the IR seeker is quite wide. So although the code above will eventually reach the IR beacon, it is highly likely that it will approach the IR beacon at an angle. So your robot will probably not facing the peg directly in front.
Last edited by MHTS on Fri Nov 30, 2012 1:50 am, edited 1 time in total.
|
Thu Nov 29, 2012 6:54 pm |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
I used the code you suggested and ended up with these errors: Any idea why it's not working? (I do have the driver suite installed.)
|
Thu Nov 29, 2012 7:07 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
First, irSeeker is how we named our sensor. Yours may name it differently. You need to use your sensor's name in place of irSeeker (or change your sensor's name to irSeeker). Secondly, IRSEEKER_KP is the proportional PID constant that you need to define. This constant needs to be tuned. You may want to start with a value of say 20. Thirdly, the FORWARD_POWER is the constant to determine how fast the robot should approach the peg, I would define it to 50. Fourthly, leftMotor and rightMotor are the names for your left and right wheel motors. Obviously, you need to change them to reflect the names you have given them. In other words:
|
Thu Nov 29, 2012 7:13 pm |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
I get it now! It finally clicked in my head. Thanks for all the help. It takes me a while to get things.
|
Thu Nov 29, 2012 7:29 pm |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
This is my exact code:  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTServo, none, none) #pragma config(Sensor, S2, irSeeker, sensorI2CCustom) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop) #pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone) #pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone) #pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone) #pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone) #pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone) #pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone) #include "drivers/hitechnic-irseeker-v2.h" #define IRSEEKER_KP 20 #define FORWARD_POWER 50 #define BOUND(n) (((n) < -100)? -100: ((n) > 100)? 100: (n)) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() {
int prevDir = HTIRS2readACDir(irSeeker); while (true) { int currDir = HTIRS2readACDir(irSeeker); if (currDir == 0) { // // Did not detect any IR signal, use previous direction. // currDir = prevDir; }
int turnPower = (5 - currDir)*IRSEEKER_KP; motor[motorE] = BOUND(FORWARD_POWER - turnPower); motor[motorD] = BOUND(FORWARD_POWER - turnPower); prevDir = currDir;
wait1Msec(100); } } |  |  |  |  |
All it does is spin around, but it pauses for a second if you put the IR beacon in front of it. Help? By the way, one of our motors is reversed, does that have something to do with it?
|
Thu Nov 29, 2012 9:46 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
That's why you need to tune the constants. I would reduce IRSEEKER_KP to 10 and see it that works better. At the end, you should be able to hold the IR beacon in front of the robot and run around with it and the robot should follow you.
|
Fri Nov 30, 2012 1:35 am |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: NXT Light Sensor IR
BTW, upon closer examination of your code, I spotted a problem. I don't know which motor is left and which one is right but the left one should subtract turnPower and the right one should add turnPower. Please make sure the motors have the correct "reversed" set so that positive power will turn that side forward.
|
Fri Nov 30, 2012 1:50 am |
|
 |
Alder
Rookie
Joined: Thu Oct 04, 2012 8:51 pm Posts: 22
|
 Re: NXT Light Sensor IR
Just a question for programs like this, will it always work to use Or will sometimes I have to do something else like in this code? By the way, thx for all the help. 
|
Thu Dec 06, 2012 7:29 pm |
|
|
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
|
|