ROBOTC.net forums
http://robotc.net/forums/

Turning tetrix motors with encoders
http://robotc.net/forums/viewtopic.php?f=52&t=2213
Page 1 of 1

Author:  shoeshine [ Sat Feb 20, 2010 11:26 pm ]
Post subject:  Turning tetrix motors with encoders

I need help with programming tetrix motor encoders and turning. So far I have been able to reset the encoder, drive straight for a specified distance, stop but when I reset encoders and set motors to turn 90 degrees the robot just spins nonstop. Any suggestions.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Motor,  motorA,          ballfeederleft, tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          ballfeederright, tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     leftdrive,     tmotorNormal, openLoop, reversed, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     rightdrive,    tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     shooter,       tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     collecter,     tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                           Autonomous Mode Code Template
//
// This file contains a template for simplified creation of an autonomous program for an TETRIX robot
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    initializeRobot
//
// Prior to the start of autonomous mode, you may want to perform some initialization on your robot.
// Things that might be performed during initialization include:
//   1. Move motors and servos to a preset position.
//   2. Some sensor types take a short while to reach stable values during which time it is best that
//      robot is not moving. For example, gyro sensor needs a few seconds to obtain the background
//      "bias" value.
//
// In many cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
  // Place code here to sinitialize servos to starting positions.
  // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

  return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                         Main Task
//
// The following is the main code for the autonomous robot operation. Customize as appropriate for
// your specific robot.
//
// The types of things you might do during the autonomous phase (for the 2008-9 FTC competition)
// are:
//
//   1. Have the robot follow a line on the game field until it reaches one of the puck storage
//      areas.
//   2. Load pucks into the robot from the storage bin.
//   3. Stop the robot and wait for autonomous phase to end.
//
// This simple template does nothing except play a periodic tone every few seconds.
//
// At the end of the autonomous period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

task main()
{
  initializeRobot();

  waitForStart(); // Wait for the beginning of autonomous phase.

  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////
  ////                                                   ////
  ////    Add your robot specific autonomous code here.  ////
  ////                                                   ////
  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////




  nMotorEncoder[leftdrive] =0;
  nMotorEncoder[rightdrive] = 0;

  while(nMotorEncoder[leftdrive] < 11000)

  {
    motor[leftdrive] = 60;
    motor[rightdrive] = 60;
  }
  motor[leftdrive] = 0;
  motor[rightdrive] = 0;

  wait1Msec(1000);

  nMotorEncoder[leftdrive] = 0;
  nMotorEncoder[rightdrive] = 0;

  while(nMotorEncoder[leftdrive] < 720)

  {
    motor[leftdrive] = 25;
    motor[rightdrive] = 75;
  }
  motor[leftdrive] = 0;
  motor[rightdrive] = 0;

  wait1Msec(100);

  nMotorEncoder[leftdrive] = 0;
  nMotorEncoder[rightdrive] = 0;


  while(nMotorEncoder[leftdrive] < 360)

  {
    motor[leftdrive] = 30;
    motor[rightdrive] = 30;
  }
  motor[leftdrive] = 0;
  motor[rightdrive] = 0;

  wait1Msec(100);

  nMotorEncoder[leftdrive] = 0;
  nMotorEncoder[rightdrive] = 0;




}


Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/