View unanswered posts | View active topics It is currently Thu Oct 30, 2014 6:58 pm






Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
NXT Light Sensor IR 
Author Message
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: NXT Light Sensor IR
You can tell the program which motors are flipped in the "Motor and Sensor Setup" window, where you configure controllers. There're checkboxes on the right that allow you to enable specific options for each motor.


Thu Dec 06, 2012 7:45 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT Light Sensor IR
Alder wrote:
Just a question for programs like this, will it always work to use
Code:
   bMotorReflected[motorD] = true;
   bMotorReflected[motorE] = false;


Or will sometimes I have to do something else like in this code?
By the way, thx for all the help. :)

I don't use bMotorReflected. It should work but I would recommend doing this only with the Motor and Sensor setup dialog which will generate the pragmas with the correct "reversed" keyword. Don't mix them. Use one or the other or you will confuse yourself (or others) pretty quickly. I would still recommend doing it the pragma way because that's a single place you need to go check for the motor polarities. If you use bMotorReflected, then you have to search all over the code to see where, when and who is programming the motor with different polarities. Imagine the scenario where you program a motor with bMotorReflected in one code path and then forgot about it. Later on you decided the polarity of a motor was wrong and you program it again with bMotorReflected in another code path. Very soon, you will have bugs when you execute one code path, the motor turns one way, but another code path, the motor turns the other way. That would be very messy to debug.


Thu Dec 06, 2012 7:52 pm
Profile
Rookie
User avatar

Joined: Thu Oct 04, 2012 8:51 pm
Posts: 22
Post Re: NXT Light Sensor IR
K, so when I change the code to work with the flipped motors, it just goes forward instead of spinning around and does nothing if the IR sensor is right in front of it. How do I get it to just stand still until the IR beacon is turned on?
Code:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S2,     irSeeker,              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)
#include "drivers/hitechnic-irseeker-v2.h"
#define IRSEEKER_KP      10
#define FORWARD_POWER    50
#define BOUND(n)  (((n) < -100)? -100: ((n) > 100)? 100: (n))
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
    bMotorReflected[motorD] = true;
   bMotorReflected[motorE] = false;

int prevDir = HTIRS2readACDir(irSeeker);
while (true)
{
    int currDir = HTIRS2readACDir(irSeeker);
    if (currDir == 0)
    {

        currDir = prevDir;
    }


    int turnPower = (5 - currDir)*IRSEEKER_KP;
    motor[motorE] = BOUND(FORWARD_POWER + turnPower);
    motor[motorD] = BOUND(FORWARD_POWER + turnPower);
    prevDir = currDir;

    wait1Msec(100);
}
}


Sun Dec 09, 2012 7:05 pm
Profile
Rookie
User avatar

Joined: Thu Oct 04, 2012 8:51 pm
Posts: 22
Post Re: NXT Light Sensor IR
Nevermind!
I finally understood what was wrong.
Thanks again for all the help! (and bearing with my very slow understanding)


Tue Dec 11, 2012 5:37 pm
Profile
Rookie

Joined: Tue Dec 11, 2012 9:19 pm
Posts: 47
Post Re: NXT Light Sensor IR
MHTS wrote:
The above code will keep driving towards the IR. Obviously, you need to determine and add code on when it should stop. Also note that zone 5 of the IR seeker is quite wide. So although the code above will eventually reach the IR beacon, it is highly likely that it will approach the IR beacon at an angle. So your robot will probably not facing the peg directly in front.


+1. It is pretty much impossible to align to
the peg using the IR beacon alone. That's why
the FTC people put white tape on the platform.

The IR beacon can be used to determine only
which peg the beacon is on. This can be accomplished
by dead reckoning to the center of the platform, orienting
the receiver straight on and then taking a single reading.

If your dead reckoning is done right, if the beacon is
on the center peg, you should see a reading of 5, less
than that and the beacon is on the left peg, greater, on
the right.

You may then use a light sensor to find the appropriate
white line to align precisely with the peg.


Mon Dec 24, 2012 12:39 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: NXT Light Sensor IR
skatefriday wrote:
MHTS wrote:
The above code will keep driving towards the IR. Obviously, you need to determine and add code on when it should stop. Also note that zone 5 of the IR seeker is quite wide. So although the code above will eventually reach the IR beacon, it is highly likely that it will approach the IR beacon at an angle. So your robot will probably not facing the peg directly in front.


+1. It is pretty much impossible to align to
the peg using the IR beacon alone. That's why
the FTC people put white tape on the platform.

The IR beacon can be used to determine only
which peg the beacon is on. This can be accomplished
by dead reckoning to the center of the platform, orienting
the receiver straight on and then taking a single reading.

If your dead reckoning is done right, if the beacon is
on the center peg, you should see a reading of 5, less
than that and the beacon is on the left peg, greater, on
the right.

You may then use a light sensor to find the appropriate
white line to align precisely with the peg.

Actually, it is possible to seek and go to the IR beacon peg with IR seeking alone. Our team did it. Here are a few videos demonstrating that.
http://www.youtube.com/watch?v=ou8zFzWXQ7I
http://www.youtube.com/watch?v=QJxVKs7WrBg
http://www.youtube.com/watch?v=tSgsu24BEd8
http://www.youtube.com/watch?v=XFNdUPryXh4


Mon Dec 24, 2012 2:33 am
Profile
Rookie

Joined: Wed Oct 05, 2011 2:49 pm
Posts: 12
Post Re: NXT Light Sensor IR
How consistently does your autonomous score?
Greater than 80%?


Tue Feb 12, 2013 1:07 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


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.