Page 1 of 1

IRSeeker connecting to IRBall

Posted: 07 Jan 2012, 16:01
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

Re: IRSeeker connecting to IRBall

Posted: 07 Jan 2012, 18:30
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

Re: IRSeeker connecting to IRBall

Posted: 08 Jan 2012, 13:48
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

Re: IRSeeker connecting to IRBall

Posted: 08 Jan 2012, 14:15
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

Re: IRSeeker connecting to IRBall

Posted: 08 Jan 2012, 18:09
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

Re: IRSeeker connecting to IRBall

Posted: 09 Jan 2012, 01:48
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