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

IR code for tetrix
http://robotc.net/forums/viewtopic.php?f=1&t=10288
Page 1 of 2

Author:  JAYPD [ Sun Jan 18, 2015 6:19 pm ]
Post subject:  IR code for tetrix

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#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)
#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 !!*//

/**
* hitechnic-irseeker-v2.h provides an API for the HiTechnic IR Seeker V2. This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
*
* Credits:
* - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER

* Xander Soldaat (xander_at_botbench.com)
* Dick Swan
* Gus Jansson
* 04 October 2012
* version 0.1
*/

#include "hitechnic-irseeker-v2.h"

// main task
task main ()
{
displayCenteredTextLine(0, "HiTechnic");
displayCenteredBigTextLine(1, "IR Seekr");
displayCenteredTextLine(3, "Test 1");
displayCenteredTextLine(5, "Press enter to");
displayCenteredTextLine(6, "switch between");
displayCenteredTextLine(7, "600 and 1200 Hz");
sleep(2000);

// Create struct to hold sensor data
tHTIRS2 irSeeker;

// Initialise and configure struct and port
initSensor(&irSeeker, S1);

while(true)
{
// You can switch between the two different DSP modes by pressing the
// orange enter button

playSound(soundBeepBeep);
while(bSoundActive)
{}
eraseDisplay();

// display the current DSP mode
if (irSeeker.mode == DSP_1200)
displayTextLine(0, " DC 1200");
else
displayTextLine(0, " DC 600");

while (true)
{
if (getXbuttonValue(xButtonEnter))
{
// "Enter" button has been pressed. Need to switch mode

irSeeker.mode = (irSeeker.mode == DSP_1200) ? DSP_600 : DSP_1200;
while(getXbuttonValue(xButtonEnter))
{
sleep(1);
}
break;
}

// Read the sensor data.
readSensor(&irSeeker);
displayTextLine(1, "D:%4d %4d 3%d", irSeeker.dcDirection, irSeeker.acDirection, irSeeker.enhDirection);
displayTextLine(2, "0:%4d %d", irSeeker.dcValues[0], irSeeker.acValues[0]);
displayTextLine(3, "0:%4d %4d", irSeeker.dcValues[1], irSeeker.acValues[1]);
displayTextLine(4, "0:%4d %4d %3d", irSeeker.dcValues[2], irSeeker.acValues[2], irSeeker.enhStrength);
displayTextLine(5, "0:%4d %4d", irSeeker.dcValues[3], irSeeker.acValues[3]);
displayTextLine(6, "0:%4d %4d", irSeeker.dcValues[4], irSeeker.acValues[4]);
displayTextLine(7, "Enter to switch");
}
}
}

This is my code, can some one show me how to make a tetrix bot with IRseeker chase an IRBeacon?

Author:  JAYPD [ Sun Jan 18, 2015 6:24 pm ]
Post subject:  Re: IR code for tetrix

I don't mean to make it seem like I want people to do my work for me, but I need the code so I can understand IRSeekers better :?

Author:  FTC_359 [ Sun Jan 18, 2015 8:10 pm ]
Post subject:  Re: IR code for tetrix

Quite frankly Xander's 3rd party driver suite is not necessary for the IR unless you want to access it through a SMUX or check its individual sensor strengths.

To access its value without the drivers, simply use
Code:
SensorValue[NameOfIRHere]


It will return a value between 0-9, with 0 being no signal detected and 1-9 representing different zones.

To view these different zones in a sketch and how to use and/or program other sensors, refer to this guide.

In the future, please do not spam the forums with the same general question; post one thread and be specific. Also, please do not post consecutive posts; edit your post instead unless your intent is to bring attention back to the thread, which you should only generally do after 2 days of no responses.

Author:  MHTS [ Sun Jan 18, 2015 8:14 pm ]
Post subject:  Re: IR code for tetrix

You can play with the below code for a start. If tune correctly, this code will make the robot turn to wherever your IR beacon is. But you need to change the "leftMotor" and "rightMotor" to your motor D or E. I don't know which one is your left motor. The following code assumes you have a single IR seeker facing forward. You will notice you have to move the IR beacon quite a bit before the robot will start turning towards it. This is because zone 5 has a very wide angle. If you turn the IR seeker sideway say to the right, then you change 5.0 to 2.0, you will have a better response.
Code:
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#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)
#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 !!*//

#define Kp              20.0

task main()
{
    tHTIRS2 irSeeker;
    initSensor(&irSeeker, S2);
    while (true)
    {
        readSensor(&irSeeker);
        float error = irSeeker.acDirection - 5.0;
        motor[leftMotor] = Kp*error;
        motor[rightMotor] = -Kp*error;
        wait1Msec(20);
    }
}

Author:  JAYPD [ Tue Jan 20, 2015 12:58 pm ]
Post subject:  Re: IR code for tetrix

Thanks, I will try this code

Author:  JAYPD [ Tue Jan 20, 2015 1:02 pm ]
Post subject:  Re: IR code for tetrix

well, there were a few issues, but not many

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#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)
#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 !!*//

#define Kp 20.0

task main()
{
tHTIRS2 irSeeker;
initSensor(&irSeeker, S2);
while (true)
{
readSensor(&irSeeker);
float error = irSeeker.acDirection - 5.0;
motor[motorD] = Kp*error;
motor[MotorE] = -Kp*error;
wait1Msec(20);
}
}

Author:  JAYPD [ Tue Jan 20, 2015 1:22 pm ]
Post subject:  Re: IR code for tetrix

This code is 100% foreign, I am familiar with the concept, but the coding is a distance from any other coding I ever done

Author:  MHTS [ Tue Jan 20, 2015 11:54 pm ]
Post subject:  Re: IR code for tetrix

JAYPD wrote:
well, there were a few issues, but not many

What are the issues? Sorry I can't read your mind!

Author:  MHTS [ Tue Jan 20, 2015 11:55 pm ]
Post subject:  Re: IR code for tetrix

JAYPD wrote:
This code is 100% foreign, I am familiar with the concept, but the coding is a distance from any other coding I ever done

What do you not understand? You need to ask specific questions.

Author:  JAYPD [ Wed Jan 21, 2015 11:27 am ]
Post subject:  Re: IR code for tetrix

The issues are highlighted in the code, the only code that needs fixed is highlighted red. What I don't understand well is the coding of the IR seeker, Its just dumbfounding for me. I have never interacted with coding before september, and the team mmeets3 dyas a weekk, since the last competition on the 10th

Author:  FTC_359 [ Wed Jan 21, 2015 11:43 am ]
Post subject:  Re: IR code for tetrix

It's because you need to include the driver...

Author:  JAYPD [ Wed Jan 21, 2015 1:04 pm ]
Post subject:  Re: IR code for tetrix

FTC_359 wrote:
It's because you need to include the driver...


I thought that meant the one in control of the robot, but I can see now that it is not, there is much more to this than what I know. the purpose of this journey is to learn more about this amazing world of coding, and, the world in general. I will research what this means.
epistemology is key

Author:  JAYPD [ Wed Jan 21, 2015 1:13 pm ]
Post subject:  Re: IR code for tetrix

I added the driver now the only problems are the motor commands now what

Author:  JAYPD [ Wed Jan 21, 2015 1:16 pm ]
Post subject:  Re: IR code for tetrix

JAYPD wrote:
FTC_359 wrote:
It's because you need to include the driver...


I thought that meant the one in control of the robot, but I can see now that it is not, there is much more to this than what I know. the purpose of this journey is to learn more about this amazing world of coding, and, the world in general. I will research what this means.
epistemology is key


I'm really tired, I don't know why I said that :|

Author:  MHTS [ Wed Jan 21, 2015 2:07 pm ]
Post subject:  Re: IR code for tetrix

I assume the code compiled without issues now? If so this code should allow you to move the IR beacon in front of the robot and it will turn to follow the beacon. If the robot spins the other way, it means your left and right motors are switched (i.e. the code was assuming motorD is your left motor).
After you got that working, then you think about how to apply that code to do what you want it to do.

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