View unanswered posts | View active topics It is currently Sun Nov 17, 2019 8:14 am






Reply to topic  [ 7 posts ] 
Help with IR Seeker 
Author Message
Rookie

Joined: Wed Jan 07, 2015 5:08 pm
Posts: 5
Post Help with IR Seeker
Can some tell me what is wrong on Line 111? I have tried everything I know and still can't get it to work.


Attachments:
Autonomous 01062015.c [5.41 KiB]
Downloaded 386 times
Wed Jan 07, 2015 6:20 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Help with IR Seeker
What version of ROBOTC are you using? If you're using version 4, the way the 3rd party drivers are structured has changed, so HTIRS2readACDir doesn't exist anymore. In version 4, there's only one function that gets all of the data from the sensor and puts it into a single structure. At https://github.com/botbench/robotcdriversuite you can download the latest version of the drivers, plus it has an explanation of the new driver format.

_________________
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/.


Thu Jan 08, 2015 9:57 am
Profile
Rookie

Joined: Wed Jan 07, 2015 5:08 pm
Posts: 5
Post Re: Help with IR Seeker
We are using version 4


Thu Jan 08, 2015 12:43 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Help with IR Seeker
Okay, so you do have the new structure, where HTIRS2readACDir doesn't exist. See the hitechnic-irseeker-v2-test1 sample program for the new way to use and get data from the IR sensor.

_________________
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/.


Thu Jan 08, 2015 1:57 pm
Profile
Rookie

Joined: Wed Jan 07, 2015 5:08 pm
Posts: 5
Post Re: Help with IR Seeker
Cool thanks, but now I'm total confused.

We are a rookie team and my programming skills are to say the least very weak. I really don't understand how to get the bot to turn towards the beacon and how to align the bot when the beacon is at an angle or some other alignment other then straight on the beacon.

Do you have any tutorials or documentation that could help us?


Thu Jan 08, 2015 3:58 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Help with IR Seeker
This is how you modify your code to use the new IRSeeker driver in version 4.x. This will compile without error but it doesn't mean the code will work correctly as you intended. The next step is to figure out what you intend it to do and how to program the code correspondingly.
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S2,     IRseeker,       sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                           Autonomous Mode Code Template
//
// This file contains a template for simplified creation of an autonomous program for an Tetrix robot
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.
#include "Sample Programs\NXT\3rd Party Driver Library\include\hitechnic-irseeker-v2.h" //

tHTIRS2 irSeeker;

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    initializeRobot
//
// Prior to the start of autonomous mode, you may want to perform some initialization on your robot.
// Things that might be performed during initialization include:
//   1. Move motors and servos to a preset position.
//   2. Some sensor types take a short while to reach stable values during which time it is best that
//      robot is not moving. For example, gyro sensor needs a few seconds to obtain the background
//      "bias" value.
//
// In many cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
    //int IR =0;
    // Place code here to sinitialize servos to starting positions.
    // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
    initSensor(&irSeeker, IRseeker);
    return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                         Main Task
//
// The following is the main code for the autonomous robot operation. Customize as appropriate for
// your specific robot.
//
// The types of things you might do during the autonomous phase (for the 2008-9 FTC competition)
// are:
//
//   1. Have the robot follow a line on the game field until it reaches one of the puck storage
//      areas.
//   2. Load pucks into the robot from the storage bin.
//   3. Stop the robot and wait for autonomous phase to end.
//
// This simple template does nothing except play a periodic tone every few seconds.
//
// At the end of the autonomous period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

task main()
{
   
    initializeRobot();

    //waitForStart(); // Wait for the beginning of autonomous phase.
    long IRval = 0;
    wait1Msec(3000);
    ///////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////
    ////                                                   ////
    ////    Add your robot specific autonomous code here.  ////
    ////                                                   ////
    ///////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////

    while (true)
    {
        motor[motorD]=50;  //travel off the ramp
        motor[motorE]=50;
        wait1Msec(3000);        //pause

        motor[motorD]=0; //stop motors for one second
        motor[motorE]=0;      // it stops to get straight for it to turn
        wait1Msec(1000);  // pause

        motor[motorD]=50;  //turning counterclockwise
        motor[motorE]=-50;
        wait1Msec(900);      //pause

        motor[motorD]=0;  // rest for a second find the ir sensor and number
        motor[motorE]=0;
        wait1Msec(1000);      //pause

        readSensor(&irSeeker);
        IRval = irSeeker.acDirection;

        if (IRval==5)      //condition: looking straight at the ir sensor}
        {
            while (IRval!=6)      //turn robot until ir sensor reads six
            {motor[motorD]=50;      //makes turn counterclockwise
                readSensor(&irSeeker);
                IRval=irSeeker.acDirection; // rechecks sensor
            }
            motor[motorD]=0;    // stops turning

            while (IRval!=7)      //keeps going straight until ir sensor reads 7
            {motor[motorD]=50;
                motor[motorE]=50;
                readSensor(&irSeeker);
                IRval=irSeeker.acDirection; // rechecks sensor
            }

            motor[motorD]=0;       // stops motor
            motor[motorE]=0;       // stops motor

            while (IRval!=6)       //rotate motor d till ir reads 6
            { motor[motorE]=50;
                motor[motorD]=-50;
                readSensor(&irSeeker);
                IRval=irSeeker.acDirection; // rechecks sensor
            }
        }
        motor[motorD]=100; //go foward towards tower
        motor[motorE]=100;
        wait1Msec(4000);
    }
}


Thu Jan 08, 2015 4:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Help with IR Seeker
The first problem is that the majority of your code is in a forever-loop. In autonomous, you usually just execute your routine once not repeatedly especially running down the ramp part. Let's start out by writing some pseudo-code in English. For example, according to your current code:
Code:
forever-loop
{
    travel off the ramp at 50% power for 3 seconds;
    stop for 1 second;
    turn counter-clockwise at 50% power for 900 msec;
    stop for 1 second;
    if (IR beacon is right in front)
    {
        turn robot counter-clockwise until IR reads 6;
        keep going straight until IR reads 7;
        turn robot clockwise until IR reads 6;
    }
    go straight full speed for 4 seconds;
}

From reading your algorithm in English, I don't see how this code will work. You need to write out an algorithm in English what you intend it to do and then we can try translating it into code.
BTW, are you trying to score the center goal or are you trying to knock down the kick stand or both, like this?
https://www.youtube.com/watch?v=R3-2054 ... fWSaaI_OtA


Thu Jan 08, 2015 5:02 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.