View unanswered posts | View active topics It is currently Wed Jul 30, 2014 1:35 am






Reply to topic  [ 4 posts ] 
NXT Motor Encoder Problem 
Author Message
Rookie

Joined: Sun Nov 02, 2008 6:28 pm
Posts: 6
Post NXT Motor Encoder Problem
I'm trying to practice with encoders using the built in NXT Lego motor encoders.

With this code the NXT Lego motors are doing more than 2 rotations and the program continuously loops.
How can I make it just rotate twice and stop afterwards?
Does one rotation on NXT Lego motors not equal 1500 on the encoders?

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/* The code above this comment was automatically generated by ROBOTC based on the Motors
 * and Sensors Setup command under the Robot menu. */

/*
 * RC_Dual --- Put either autonomous or teleop code in this program using ROBOTC
 *
 *  This program is written for ROBOTC version 1.46 and to be used for the FIRST
 *  Tech Challenge tournaments.  It is a dual-mode program where either the autonomous
 *  or tele-op portions of the code are in this program.  You should make copies of this
 *  program for your teleop code and another one for your autonomous code and add to it
 *
 *
 *  This program is protected by United States copyright law and may not be
 *  reproduced, distributed, transmitted, displayed or published without the
 *  prior written permission of FIRST, NPO Services, LLC or Mannie Lowe.  You
 *  may not alter or remove any copyright or other notice from copies of the
 *  content.  However, you are free to use this source code for your personal,
 *  non-commercial use.
 *  Copyright ©2008 NPO Services, LLC - Mannie Lowe.  All rights are reserved.
 *
 *
 */

#include "JoystickDriver.c"

void stopMotors()
{
  /* This subroutine only stops the 12V motors defined in the Motors and Sensors setup area.
   * If you add more motors and or servos, please update this routine to stop their movement. */

  motor[motorB] = 0;
  motor[motorA] = 0;

  /* If you have servos, a way to stop their movement is with the following code:
  servoTarget[servo1] = ServoValue[servo1];
  */
}

task main()
{
  while (true)
  {
    getJoystickSettings(joystick);

    // has the FMS stopped the program
    if (joystick.StopPgm)
    {
      nxtDisplayTextLine(2, "Disabled");
      stopMotors();
      wait1Msec(50);
      continue;   // go back into top of while loop
    }

    nxtDisplayTextLine(2, "Enabled");

    /* put the rest of your code here */

    nMotorEncoder[motorB] = 0;
    nMotorEncoder[motorA] = 0;

    nMotorEncoderTarget[motorB] = 3000;
    nMotorEncoderTarget[motorA] = 3000;

    motor[motorB] = 50;
    motor[motorA] = 50;

    while(nMotorRunState[motorB] != runStateIdle || nMotorRunState[motorA] != runStateIdle)
    {
      //Idle Loop
    }
  }
}


Tue Nov 18, 2008 10:24 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post Re: NXT Motor Encoder Problem
The NXT motors are in degrees... so one rotation is equal to 360.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Nov 19, 2008 12:21 pm
Profile
Rookie

Joined: Sun Nov 02, 2008 6:28 pm
Posts: 6
Post Re: NXT Motor Encoder Problem
tfriez wrote:
The NXT motors are in degrees... so one rotation is equal to 360.

ok thanks.
Now why won't the program stop after it has rotated?


Wed Nov 19, 2008 5:10 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post Re: NXT Motor Encoder Problem
The program won't stop because of the Joystick Driver is it's own background task... and ROBOTC won't stop the program until all of the tasks are completed (in the FTC sake, the JoystickInclude will never stop unless told).

On the field, you shouldn't worry, as the Field Management System will forcefully stop your program when the autonomous period is over.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Nov 26, 2008 10:57 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.