View unanswered posts | View active topics It is currently Tue Jul 29, 2014 7:28 pm






Reply to topic  [ 3 posts ] 
What could be wrong here? 
Author Message
Rookie

Joined: Mon Mar 24, 2014 3:13 pm
Posts: 2
Post What could be wrong here?
I am running ROBOTC v3.62 for MINDOSTORMS and I have the following code for driving forward:

void move(float inches)
{
int tics;
int enc;

tics = (int)(inches / 7 * 360);
nMotorEncoder[rightMotor] = 0;

while (ABS(nMotorEncoder[rightMotor]) < tics)
{
if (inches > 0)
{
motor[rightMotor] = 20;
motor[leftMotor] = 20;
}
else
{
motor[rightMotor] = -20;
motor[leftMotor] = -20;
}
enc = ABS(nMotorEncoder[rightMotor]);
}
motor[rightMotor] = 0;
motor[leftMotor] = 0;

wait1Msec(2000);
}

I added the "enc" so I could view the ABS(nMotorEncoder[rightMotor]) values within the debugger. When I call the function, it seems as if everything works in terms of getting the correct values for both "tics" and "enc" and if I step through the code the "enc" values increase predictably. The problem is that the loop WILL NOT EXIT regardless of the encoder values. For example "tics" will be 308 and the "enc" will go much greater than that and yet the code will continue looping regardless. The motors continually run forward and I never see them stop for the 2 seconds I am expecting. Please help if you have any insight into this problem.


Mon Mar 24, 2014 3:19 pm
Profile
Rookie

Joined: Mon Mar 24, 2014 3:13 pm
Posts: 2
Post Re: What could be wrong here?
My bad... I forgot to put parenthesis around my #define of ABS.... sorry for the waste of time...


Mon Mar 24, 2014 3:25 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: What could be wrong here?
That's okay. You do know about the built-in abs() though, right?

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Tue Mar 25, 2014 3:37 pm
Profile
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.