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

IR seeker Woes
http://robotc.net/forums/viewtopic.php?f=52&t=10069
Page 1 of 1

Author:  wickedcthuhlu [ Mon Dec 22, 2014 3:19 pm ]
Post subject:  IR seeker Woes

We cannot seem to get Xander's program to work in the aspect of moving the robot, as with all other code's I've found online. Every one of them either confuses us or produces errors. Mostly the latter. We can use his program to read the sensors and display the information but we cannot get the readings to move the robot. This is our first year working with the Hi-technic IR sensors and our first year working with IR in general. Any advice or example code would be greatly appreciated.

Author:  MHTS [ Mon Dec 22, 2014 3:41 pm ]
Post subject:  Re: Coding Woes

Would you post the code you have problems with?

Author:  wickedcthuhlu [ Tue Dec 23, 2014 1:58 pm ]
Post subject:  Re: Coding Woes

MHTS wrote:
Would you post the code you have problems with?


Code:
#pragma config(Sensor, S2,     HTIRS2,         sensorI2CCustom)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)a
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "hitechnic-irseeker-v2.h"

void initializeRobot()
{
   //Place code here to sinitialize servos to starting positions


    return;
}

task main()
{
   //sets up the ir seeker
   tHTIRS2 irSeeker;
  initSensor(&irSeeker, S1);

  //starts auton
   initializeRobot();

  //gets robot of ramp
   motor[motorD] = 50;
   motor[motorE] = 50;
   wait1Msec(3000);
   motor[motorD] = 0;
   motor[motorE] = 0;
   wait1Msec(1000);



   //infinite loop to find the ir beacon
   while (true) {
   readSensor(&irSeeker);
   if (irSeeker.dcValues[0]) {
      motor[motorD] = 50;
      motor[motorE] = -50;
      wait1Msec(500);
      motor[motorD] = 50;
      motor[motorE] = 50;
      wait1Msec(3000);
   }
   if (irSeeker.dcValues[1] > 0) {
      motor[motorD] = 50;
      motor[motorE] = -50;
      wait1Msec(250);
      motor[motorD] = 50;
      motor[motorE] = 50;
      wait1Msec(3000);
   }
   if (irSeeker.dcValues[2] > 0) {
      motor[motorD] = 50;
      motor[motorE] = 50;
      wait1Msec(3000);
   }
   if (irSeeker.dcValues[3] > 0) {
      motor[motorD] = -50;
      motor[motorE] = 50;
      wait1Msec(250);
      motor[motorD] = 50;
      motor[motorE] = 50;
      wait1Msec(3000);
   }
   if (irSeeker.dcValues[4] > 0) {
      motor[motorD] = -50;
      motor[motorE] = 50;
      wait1Msec(500);
      motor[motorD] = 50;
      motor[motorE] = 50;
      wait1Msec(3000);
   }
   }
}


We're working with DC right now to get a feel to it, even though we know the AC setting needs to be used for the competition. Please help with changing this to AC and getting away from DC.

Author:  wickedcthuhlu [ Tue Dec 23, 2014 2:10 pm ]
Post subject:  Re: Coding Woes

We are also getting the error "PgmCnt: 00001E" meaning 'motors out of range' even if it's plugged into the bot.

Author:  MHTS [ Tue Dec 23, 2014 6:38 pm ]
Post subject:  Re: Coding Woes

Hmm, it looks like you are using RobotC 4.x and the corresponding new drivers from Xander's which I am not familiar with yet. So I won't comment on the usages of the IR driver because it would look incorrect to me if you were using 3.x.
In any case, just from the pure coding point of view, the code has a sequence of if's. This means that it is possible to run the code in multiple blocks of if's. Each if-block programs the same drive motors. This could present conflicts. For example, it is completely possible that both dcValues[1] and dcValues[2] are greater than 0. In that case, both if-blocks ran and your code will program the robots to turn but immediately program it to go straight although you did have wait1Msec() statements in between. So it may work but you may want to change your logic to use "if-else if" instead.
Regarding the motor-out-of-range error, unless RobotC 4.x works differently than I thought, you did not configure the motors correctly. You need to go to "Robot->Motors and Sensors setup" and in the "External controllers" tab, you need to select "Standard Tetrix configuration" and go to the "motors" tab and name your motors etc.

Author:  wickedcthuhlu [ Sat Jan 03, 2015 1:42 pm ]
Post subject:  Re: Coding Woes

We're still unsure on how to fix the code, and we are having trouble trying to figure out what to do with the if/else if statements. We've changed the code but we can't get it to work with the bot in the way we need it to.



Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     HTIRS2,         sensorI2CCustom)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "hitechnic-irseeker-v2.h"

void initializeRobot()
{
   //Place code here to sinitialize servos to starting positions


   return;
}

task main()
{
   //sets up the ir seeker
   tHTIRS2 irSeeker;
   initSensor(&irSeeker, S2);

   //starts auton
   initializeRobot();

   //gets robot of ramp
   motor[motorD] = 50;
   motor[motorE]= 50;
   wait1Msec(3000);
   motor[motorD]= 0;
   motor[motorE]= 0;
   wait1Msec(1000);



   //infinite loop to find the ir beacon
   while (true) {
      readSensor(&irSeeker);
      motor[motorD] = 50;
      motor[motorE]= 50;
      wait1Msec(5000);
      if (irSeeker.acValues[0]) {
         motor[motorD]= 50;
         motor[motorE]= -50;
         wait1Msec(250);
         motor[motorD]= 50;
         motor[motorE]= 50;
         wait1Msec(2000);
      }
      if (irSeeker.acValues[1] > 0) {
         motor[motorD]= 50;
         motor[motorE]= -50;
         wait1Msec(250);
         motor[motorD]= 50;
         motor[motorE]=50;
         wait1Msec(2000);
      }
      if (irSeeker.acValues[2] > 0) {
         motor[motorD]=50;
         motor[motorE]=50;
         wait1Msec(2000);
      }
      if (irSeeker.acValues[3] > 0) {
         motor[motorD]=-50;
         motor[motorE]=50;
         wait1Msec(250);
         motor[motorD]=50;
         motor[motorE]=50;
         wait1Msec(3000);
      }
      if (irSeeker.acValues[4] > 0) {
         motor[motorD]=-50;
         motor[motorE]=50;
         wait1Msec(500);
         motor[motorD]=50;
         motor[motorE]=50;
         wait1Msec(3000);
      }
   }
}

Author:  BurningLights [ Sun Jan 04, 2015 1:33 am ]
Post subject:  Re: IR seeker Woes

What is your robot doing incorrectly? That might help us to track down the error. One thing I do notice is that you use a series of if statements, and not one if followed by else ifs. It is actually possible for the beacon to be visible to more than one of the IR sensor's internal pickups at once, which could cause more than one of your if statements to run and maybe cause interesting behavior.

Author:  wickedcthuhlu [ Wed Jan 07, 2015 6:11 pm ]
Post subject:  Re: IR seeker Woes

BurningLights wrote:
What is your robot doing incorrectly? That might help us to track down the error. One thing I do notice is that you use a series of if statements, and not one if followed by else ifs. It is actually possible for the beacon to be visible to more than one of the IR sensor's internal pickups at once, which could cause more than one of your if statements to run and maybe cause interesting behavior.

Our problem is that the robot shows no behavior at all. The robot doesn't move, and doesn't show signs it's even reacting to the IR beacon. I've added the else-if statements but still nothing. We've looked at everything from the wires to the wifi and even if there were any blown fuses. None of these were the source of the issue so we're positive it was a coding issue.

Author:  MHTS [ Wed Jan 07, 2015 6:37 pm ]
Post subject:  Re: IR seeker Woes

Why don't you first check out if the irseeker is giving you good readings by adding the following line right after the readSensor line?
Code:
      readSensor(&irSeeker);
      nxtDisplayTextLine(1, "acDir=%d", irSeeker.acDirection);

Also, since your code is just trying to determine the direction of the IR beacon, you should really just use the acDirection instead of dealing with each individual sensor reading.

Author:  wickedcthuhlu [ Sat Jan 10, 2015 2:28 pm ]
Post subject:  Re: IR seeker Woes

We were able to get our sensor to return the readings we need, but the code itself had to be drastically changed. We now only have a few compiler errors, those being:

**Info***:Include file 'C:\Program Files (x86)\Robomatter Inc\ROBOTC Development Environment 4.x\Includes\JoystickDriver.c' has already been opened.
*Warning*:'enum' is anonymous declaration. The 'typedef' for 'tHTIRS2DSPMode' has no impact!
**Info***:'dirAC' is written but has no read references
**Info***:'_mode' is written but has no read references

and the code itself is:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     HTIRS2,         sensorNone)
#pragma config(Motor,  mtr_S1_C1_1,     leftTex,       tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     rightTex,      tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, PIDControl)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//Ir Seeker is in port 2

#include "JoystickDriver.c" //must have this for wait for start
#include "hitechnic-irseeker-v2.h"

//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
void initializeRobot() {

   return;
}

task main()
{

   initializeRobot();
   waitForStart();
   int dirAC = 0;
   int acS1, acS2, acS3, acS4, acS5 = 0;

   //makes a new reader caller _mode that reads the 1200 hertz cycles
   tHTIRS2DSPMode _mode = DSP_1200;

   //sound to indicate it completed previous code
   playSound(soundBeepBeep);

   while(true){

      //reads all the values and records it to the appropriate vairable
      HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 );
      //reads the direct current
      int dirAC = HTIRS2readACDir(HTIRS2);

      //makes sure its returning anything
      if(dirAC < 0){
         //quits loop because something is wrong with the ir seeker
         break;
      }
      //loop begins to seek the ir
      //the following fing the greatest ac value
      if ( dirAC    == 2)
      {
         motor[leftTex] = 50;
         motor[rightTex] = -50;
         wait10Msec(100);
      }
      else
      {
         motor[leftTex] = 0;
         motor[rightTex] = 0;
         wait1Msec(4);
      }
      if ( dirAC == 1)
      {
         motor[leftTex] = 30;
         motor[rightTex] = -10;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else
      {
         motor[leftTex] = 0;
         motor[rightTex] = 0;
         wait1Msec(4);
      }
      if (dirAC == 3)
      {
         motor[leftTex] = -10;
         motor[rightTex] = 30;
         wait1Msec(40);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else
      {
         motor[leftTex] = 0;
         motor[rightTex] = 0;
         wait10Msec(100);
      }
      if (dirAC == 0)
      {
         motor[leftTex] = 50;
         motor[rightTex] = -10;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else
      {
         motor[leftTex] = 0;
         motor[rightTex] = 0;
         wait1Msec(4);
      }
      if ( dirAC == 4)
      {
         motor[leftTex] = -10;
         motor[rightTex] = 50;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
      }
      else
      {
         motor[leftTex] = 0;
         motor[rightTex] = 0;
         wait1Msec(4);
      }

   }
}


I feel weird sharing all of our code but we're a newbie team when it comes to IR and need all the help we can get!
Thank all y'all so much.

Author:  MHTS [ Sat Jan 10, 2015 5:01 pm ]
Post subject:  Re: IR seeker Woes

Here is a suggestion on how to correct some of the problems. First, you had code that seems to initialize the DSP mode of the IR seeker, but that's incorrect. I fixed that. Secondly, your code with multiple if's one right after the other doesn't work because it is possible to execute a few of them and it will set the motors in conflicting values (e.g. if dirAC is not 1, the else part will stop the motors but then the next if may change them to something else).
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     HTIRS2,         sensorNone)
#pragma config(Motor,  mtr_S1_C1_1,     leftTex,       tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     rightTex,      tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, PIDControl)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//Ir Seeker is in port 2

#include "JoystickDriver.c" //must have this for wait for start
#include "hitechnic-irseeker-v2.h"

//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
void initializeRobot() {

   return;
}

task main()
{

   initializeRobot();
   waitForStart();
   int dirAC = 0;
   int acS1, acS2, acS3, acS4, acS5 = 0;

   //makes a new reader caller _mode that reads the 1200 hertz cycles
   HTIRS2setDSPMode(HTIRS2, DSP_1200);

   //sound to indicate it completed previous code
   playSound(soundBeepBeep);

   while(true){

      //reads all the values and records it to the appropriate vairable
      HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 );
      //reads the direct current
      int dirAC = HTIRS2readACDir(HTIRS2);

      //makes sure its returning anything
      if(dirAC < 0){
         //quits loop because something is wrong with the ir seeker
         break;
      }
      //loop begins to seek the ir
      //the following fing the greatest ac value
      if ( dirAC    == 2)
      {
         motor[leftTex] = 50;
         motor[rightTex] = -50;
         wait10Msec(100);
      }
      else if ( dirAC == 1)
      {
         motor[leftTex] = 30;
         motor[rightTex] = -10;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else if (dirAC == 3)
      {
         motor[leftTex] = -10;
         motor[rightTex] = 30;
         wait1Msec(40);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else if (dirAC == 0)
      {
         motor[leftTex] = 50;
         motor[rightTex] = -10;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
         wait10Msec(100);
      }
      else if ( dirAC == 4)
      {
         motor[leftTex] = -10;
         motor[rightTex] = 50;
         wait1Msec(50);
         motor[leftTex] = 40;
         motor[rightTex] = 40;
      }
      wait1Msec(20);
   }
}

Author:  JAYPD [ Thu Jan 15, 2015 1:08 pm ]
Post subject:  Re: IR seeker Woes

I have had no luck with any of these codes :evil: It is starting to irritate me Im in code RED please help me

Author:  MHTS [ Thu Jan 15, 2015 3:07 pm ]
Post subject:  Re: IR seeker Woes

JAYPD wrote:
I have had no luck with any of these codes :evil: It is starting to irritate me Im in code RED please help me

For us to help you, you need to tell us what the problems are. "Had no luck" doesn't tell us anything. You can start by telling us what version of RobotC you have (4.x or 3.x). You may also want to post your code and tell us what exactly was the issue with the code. BTW, don't post on multiple threads with the same problem. It wasted a lot of our time to realize it was the same problem.

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