View unanswered posts | View active topics It is currently Wed Aug 27, 2014 1:23 pm






Reply to topic  [ 4 posts ] 
Ir Code 
Author Message
Rookie

Joined: Thu Oct 18, 2012 10:09 pm
Posts: 1
Post 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 384 times
Thu Oct 18, 2012 10:12 pm
Profile
Rookie
User avatar

Joined: Sat Sep 03, 2011 10:03 am
Posts: 32
Post 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


Fri Oct 19, 2012 8:25 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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".


Fri Oct 19, 2012 5:00 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post 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);
  }
}


Sun Oct 21, 2012 11:46 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.