ROBOTC.net forums
http://www.robotc.net/forums/

Ir Code
http://www.robotc.net/forums/viewtopic.php?f=1&t=5003
Page 1 of 1

Author:  shooter609 [ Thu Oct 18, 2012 10:12 pm ]
Post subject:  Ir Code

Here is my code I have been trying to make but I keep getting errors.

Attachments:
IR Code.c [1.22 KiB]
Downloaded 752 times

Author:  Mentor3923 [ Fri Oct 19, 2012 8:25 am ]
Post subject:  Re: Ir Code

shooter609 wrote:
Here is my code I have been trying to make but I keep getting errors.


I downloaded your code and got a lot of compile errors due to strange characters in the first few columns leading up to the first non blank character in the line. I deleted all characters up to the first non blank and put spaces in. Errors went away.

I don't understand the logic of your program though. MotorA versus Leftdrive? Also why go forward if the IR sensor is straight ahead or to the left and backward if to the right. Don't you want to turn into the sensor?

Just my $.02

Author:  MHTS [ Fri Oct 19, 2012 5:00 pm ]
Post subject:  Re: Ir Code

I am not sure that's the right way to read the IR Seeker sensor. Please take a look at Xander's sample code hitechnic-irseeker-v2-test1.c, especially the function HTIRS2readDCDir. I haven't tried reading the raw value from the sensor, does it really give you the value 1-9? I noticed the HTIRS2_DC_DIR register is at offset 0. I don't know if SensorRaw will read the value at offset 0 for you. In any case, Xander's sample code also configures the IR seeker sensor. Your code did not. It may as well be that the default configuration is fine, but I would init it properly just to be safe.
Also, you should avoid nesting while loops like that. Try this instead:
Code:
task main()
{
    HTIRS2setDSPMode(InfraredSensor, DSP_1200);
    while (true)
    {
        int dirDC = HTIRS2readDCDir(InfraredSensor);
        if (dirDC == 5)
        {
            motor[Leftmotor] = 50;
            motor[Rightmotor] = 50;
            servo[AoD] = 180;
        }
        else if (dirDC < 5)
        {
            motor[Leftmotor] = 30;
            motor[Rightmotor] = 50;
        }
        else
        {
            motor[Leftmotor] = 50;
            motor[Rightmotor] = 30;
        }
        wait1Msec(50);
    }
}

Actually, like Mentor3923 said, I don't know what your code is trying to do nor do I know what AoD is for. motorA and motorB do not appear in your pragmas and they don't seem to be the wheel motors. So I took the liberty to interpret what you really meant. It is still incomplete because the above code does not have a "stopping condition".

Author:  amcerbu [ Sun Oct 21, 2012 11:46 pm ]
Post subject:  Re: Ir Code

I used the HiTechnic IR Seeker V.2 with an NXT/Tetrix robot running the following code. For me, at least, I was able to simply access the SensorValue[] array, and the robot got the correct values.

Code:
#pragma config(Sensor, S3,     IR1,                 sensorHiTechnicIRSeeker1200)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  int IR1value;
  while(true)
  {
    IR1value = SensorValue[IR1];
    nxtDisplayCenteredTextLine(5,"%d",IR1value);
  }
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/