View unanswered posts | View active topics It is currently Wed Jul 23, 2014 2:23 pm






Reply to topic  [ 5 posts ] 
Motor Encoder Question 
Author Message
Rookie

Joined: Mon Dec 01, 2008 11:44 pm
Posts: 3
Post Motor Encoder Question
We are having a problem getting the motor encoder code below to work. We set up the code as shown in the webinar, but it seems like we don't get through the test for "runStateIdle" to process any of the commands that follow. The robot does go to the target position, but then does not respond. Could you look at what we have and perhaps give me some ideas on how to debug / test to see where we are hanging? Perhaps a way to display the value for nmotorrunstate on the NXT screen?
-Thanks!
task main()
{
getJoystickSettings(joystick); //Update initial joystick/game values

while(joystick.StopPgm) //While the FMS says we're "disabled", keep looping
{
getJoystickSettings(joystick); //Update joystick/game values to see if enabled
wait1Msec(50); //wait 50 milliseconds
}

nMotorEncoder[motorD] = 0;
nMotorEncoder[motorE] = 0;

nMotorEncoderTarget[motorD] = 2000; // move 2000 encoder counts and stop
nMotorEncoderTarget[motorE] = 2000;

motor[motorD] = 50;
motor[motorE] = 50;

while(nMotorRunState[motorD] != runStateIdle || nMotorRunState[motorE] != runStateIdle)
{

}
wait1Msec(1000);
}


Tue Dec 02, 2008 12:01 am
Profile
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post Re: Motor Encoder Question
what do you mean by not respond? The program doesnt say anything but go to 200 count

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Thu Dec 04, 2008 5:20 pm
Profile
Rookie

Joined: Thu Jul 10, 2008 12:30 pm
Posts: 14
Post Re: Motor Encoder Question
When you say the system "does not respond", do you mean you cannot control
the robot via your joysticks? After the "while(nMotorRunState..." loop, you do not
have any joystick control code, so the robot will get to the Target encoder value,
stop, and exit your program.

Eric Grajales
Exploding Bacon
Team 1902 Coach

_________________
Eric Grajales


Thu Dec 04, 2008 5:37 pm
Profile
Rookie

Joined: Mon Dec 01, 2008 11:44 pm
Posts: 3
Post Re: Motor Encoder Question
Sorry -I should have been more clear in my question. The sample code is just the part that directs the robot to go forward until the encoders hit 2000 and the motors reach an idle state. The robot will travel whatever count we put in for the encoders. It just never does any command past that point. We have code in the program that comes after this portion to make a left hand turn, but the code apparently never executes. We've tried putting in different commands that work in other programs, but it seems like we never satisfy the while loop at the end, so it never gets to the next commands.

I was thinking that a possible reason was that the code should loop until the motorrunstate = idle, but if the run state never became idle the following code would never execute. We do have 4 wheel drive and only 2 of the 4 motors have encoders. I'm not sure where or how the motorrunstate is detected and was looking for some input from the community.
Thanks!


Thu Dec 04, 2008 11:07 pm
Profile
Rookie

Joined: Thu Jul 10, 2008 12:30 pm
Posts: 14
Post Re: Motor Encoder Question
I would add some debug statements to verify what is happening.

Before the encoder while loop, add
nxtDisplayTextLine(2, "Encoder Run - Start ");

and before the final Wait1Msec add
nxtDisplayTextLine(2, "Encoder Run - End ");

That way you can verify what is happening on the NXT.

In RobotC you can open the NXT Screen View so you can see
what the NXT display is showing on your computer.

_________________
Eric Grajales


Fri Dec 05, 2008 10:23 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.