IRSeeker connecting to IRBall

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
glenn073
Posts: 3
Joined: 07 Jan 2012, 14:51

IRSeeker connecting to IRBall

Post by glenn073 »

Hi,

Could someone please tell me why my IRSeeker does not react to my IRBall? It only goes out forward:

int powerDiff;
int powerLeft;
int powerRight;
int dir;
int se1, se2, se3, se4;
int se5, se6, se7, se8, se9;
task main() {
SetSensorLowspeed(S2);
while (true) {
if (ReadSensorHTIRSeeker2AC(S2, dir, se1, se3, se5, se7, se9))
{
powerDiff = 10 * (dir - 5);
powerRight = 50 - powerDiff;
powerLeft = 50 + powerDiff;
if (dir == 5) {
OnFwd(OUT_AC, 100);
}
if ((dir > 5) && (dir <= 9)) {
OnFwd(OUT_C, powerLeft);
OnFwd(OUT_A, powerRight);
}
if ((dir >= 1) && (dir <= 5)) {
OnFwd(OUT_A, powerRight);
OnFwd(OUT_C, powerLeft);
}
if (dir == 0) {
OnFwd(OUT_AC, 25);
}
}
}
}
}

Glenn
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: IRSeeker connecting to IRBall

Post by afanofosc »

Please make sure if you post code you put it in code tags. There is a button labeled "Code" just above the editor field where you type in your post. Just click it and it will give you an open and close code tag between which you can paste your program.

Code: Select all

#define LET_MY_ROBOT_MOVE_A_BIT_BEFORE_CHANGING_ITS_MIND_AGAIN MS_50

int powerDiff;
int powerLeft;
int powerRight;
int dir;
int se1, se2, se3, se4;
int se5, se6, se7, se8, se9;

task main()
{
  SetSensorLowspeed(S2);
  while (true)
  {
    if (ReadSensorHTIRSeeker2AC(S2, dir, se1, se3, se5, se7, se9))
    {
      NumOut( 0, LCD_LINE1, dir);
      NumOut(30, LCD_LINE1, se1);
      NumOut(60, LCD_LINE1, se3);
      NumOut( 0, LCD_LINE2, se5);
      NumOut(30, LCD_LINE2, se7);
      NumOut(60, LCD_LINE2, se9);
      powerDiff = 10 * (dir - 5);
      powerRight = 50 - powerDiff;
      powerLeft = 50 + powerDiff;
      if (dir == 5) {
        OnFwd(OUT_AC, 100);
      }
      else if ((dir > 5) && (dir <= 9)) {
        OnFwd(OUT_C, powerLeft);
        OnFwd(OUT_A, powerRight);
      }
      else if ((dir >= 1) && (dir <= 5)) {
        OnFwd(OUT_A, powerRight);
        OnFwd(OUT_C, powerLeft);
      }
      else if (dir == 0) {
        OnFwd(OUT_AC, 25);
      }
    }
    else
      Off(OUT_AC); // don't move if we can't read data
    Wait(LET_MY_ROBOT_MOVE_A_BIT_BEFORE_CHANGING_ITS_MIND_AGAIN);
  }
}
The above code is slightly modified to show the values being read from the device. Are you certain that you have a new IRBall that emits an AC signal rather than a DC signal?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
glenn073
Posts: 3
Joined: 07 Jan 2012, 14:51

Re: IRSeeker connecting to IRBall

Post by glenn073 »

Okay, thanks. Sorry for not putting my code in a code tag. It's all a bit weird. If there is a else if (dir == 0) {
in the program like in yours it seems like the robot ignores the ball most of the time but when there isn't and the robot doesn't see the ball he just continues with his previous order, for example turning to the right.

Glenn Netten
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: IRSeeker connecting to IRBall

Post by afanofosc »

afanofosc wrote:Are you certain that you have a new IRBall that emits an AC signal rather than a DC signal?
Is it a HiTechnic IRBall? Have you contacted HiTechnic support? If the ball is essentially ignored then my first guess is that it is a DC ball and you are calling the AC function. Have you tried the DC version of the API function? Also, HiTechnic has an enhanced IRSeeker2 API function on their blog for cases where the AC ball is too close, in which case the sensors get saturated so it is better to use the DC function in that situation. You can grab that code to see if it works any better for you.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
glenn073
Posts: 3
Joined: 07 Jan 2012, 14:51

Re: IRSeeker connecting to IRBall

Post by glenn073 »

Yes, it a HiTechnic ball. I bought it 1/2 months ago so I think it's quite a new one. I was working with the IRSeeker V1 but that wasn't working very vell so I bought a IRSeeker V2 at HiTechnic as well. I've also had some contact with Gus from HiTechnic Support. He helped us and actually I've never hesistated about this AC mode. I have my ball set in mode B. Allright, I want to try out to make this program in the DC Version but I don't know what the difference is between the DC and AC version and how to make a program in DC version. I have a book of yours: LEGO MINDSTORMS NXT POWER PROGRAMMING ROBOTICS IN C SECOND EDITION.But the information about this this DC/AC mode is something I can't find.

Glenn Netten
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: IRSeeker connecting to IRBall

Post by afanofosc »

HiTechnic has an enhanced IRSeeker2 API function on their blog for cases where the AC ball is too close, in which case the sensors get saturated so it is better to use the DC function in that situation. You can grab that code to see if it works any better for you.
You can look on their blog for this code or ask Gus for it. Did he have any suggestions as to why you more often than not get 0 as the direction?

You can read the help docs online.

http://bricxcc.sourceforge.net/nbc/nxcd ... ba8b8ed0da

In short, it is exactly like the AC version except that you pass in an additional variable to store the average in addition to all the other variables.

In BricxCC you'll see this function listed in the Templates and in the Code Completion popup list (Ctrl+Space).

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests