View unanswered posts | View active topics It is currently Tue Aug 04, 2015 4:14 pm






Reply to topic  [ 13 posts ] 
IR seeker Woes 
Author Message
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post 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.

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Last edited by wickedcthuhlu on Sat Jan 03, 2015 1:53 pm, edited 1 time in total.



Mon Dec 22, 2014 3:19 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1519
Post Re: Coding Woes
Would you post the code you have problems with?


Mon Dec 22, 2014 3:41 pm
Profile
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post 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.

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Tue Dec 23, 2014 1:58 pm
Profile
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post Re: Coding Woes
We are also getting the error "PgmCnt: 00001E" meaning 'motors out of range' even if it's plugged into the bot.

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Tue Dec 23, 2014 2:10 pm
Profile
Guru
User avatar

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


Tue Dec 23, 2014 6:38 pm
Profile
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post 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);
      }
   }
}

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Sat Jan 03, 2015 1:42 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post 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.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Sun Jan 04, 2015 1:33 am
Profile
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post 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.

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Wed Jan 07, 2015 6:11 pm
Profile
Guru
User avatar

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


Wed Jan 07, 2015 6:37 pm
Profile
Rookie

Joined: Thu Dec 11, 2014 7:16 pm
Posts: 6
Location: Arlington,Texas
Post 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.

_________________
By the time you get this..

the computer is already blown up as well as my brain. Whoops.


Sat Jan 10, 2015 2:28 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1519
Post 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);
   }
}


Sat Jan 10, 2015 5:01 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post 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


Thu Jan 15, 2015 1:08 pm
Profile
Guru
User avatar

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


Thu Jan 15, 2015 3:07 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 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.