View unanswered posts | View active topics It is currently Sat Aug 19, 2017 11:07 am

Reply to topic  [ 3 posts ] 
My program is disregarding a portion of code 
Author Message

Joined: Sat Dec 07, 2013 1:08 pm
Posts: 8
Post My program is disregarding a portion of code

I'm having some trouble with my program as it just seems to disregard a portion of code when running it.

#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     irSensor,       sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     motorH,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
  while(SensorValue[irSensor] != 5)
     if(SensorValue[irSensor] < 5)
        motor[motorD] = 50;
        motor[motorE] = 50;
     else (SensorValue[irSensor] == 5); [b]THIS ELSE STATEMENT[/b]
       motor[motorD] = 50;
       motor[motorE] = 50;
       motor[motorD] = 0;
       motor[motorE] = 0;

My program should have the robot move forward until the IR seeker (irSensor) has the IR beacon in area 5. The reason I have this else statement is because whenever it reaches area 5 on the IR seeker it stops short of where I need it to be. So the else statement causes it to move up a bit more. But instead of doing so it just skips it altogether.

If someone could please give me some insight on this that'd be great!

Wed Feb 12, 2014 11:26 pm
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: My program is disregarding a portion of code
Look very closely at your while loop. Your code said "while (IR reading is not 5)" then it means when you are inside the while loop, the IR is not 5 and your else is checking for 5. So it obviously will never be true.
BTW, the reason why it always stops short of aligning the IR beacon is because zone 5 is very wide (60-degree zone). So when your seeker is 30-degree off dead center of the beacon, it is already returning value 5. So your robot will stop. In order to do it more accurately, I suggest you point your IR seeker ahead to where the robot is moving so that you are looking for zone 2 (if on the left side) or zone 8 (if on the right side). Zone 2 and zone 8 are much narrower zones. So you will stop when you are aligned with the beacon.

Thu Feb 13, 2014 3:29 am

Joined: Sat Dec 07, 2013 1:08 pm
Posts: 8
Post Re: My program is disregarding a portion of code
Alright, Thanks a ton! I tried it and it's working fine. Thanks for that tidbit at the end as well, I figured that after I posted my question.

Thu Feb 13, 2014 9:39 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.