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






Reply to topic  [ 7 posts ] 
autonomous running like a bat out of hell 
Author Message
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post autonomous running like a bat out of hell
First year of programming for FTC teams. Trying Autonomous with encoders. Rear wheel drive with 2 motors (left and right). Encoders on those axles.
here is the code....
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     arm,           tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     lift,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     right,         tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     left,          tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     tail,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    pick,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    scoopright,           tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    scoopleft,            tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_6,    servo6,               tServoNone)
//*!!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()
{
   servo(scoopleft) = 190;
   servo(scoopright) = 65;                  // Place code here to sinitialize servos to starting positions.
   servo(pick) = 212;

  return;
}
*/
//___________________________________________________________________________________________________________________

task main()
{

  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;
  wait1Msec(1000);

  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 30; //turn both motors on at 30 percent power
  motor[left] = 30;
   
  motor[right] = 0; //turn both motors off
  motor[left] = 0;

}



Robot runs like Jim Thorpe on Fire. Straight ahead. Will eventually stop after it crosses the room. What am I doing wrong. Checked the wiring and encoder install. NXT Device screen show it is reading the Encoders. Please help control my robot, before I kick it :?


Thu Dec 26, 2013 8:33 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: autonomous running like a bat out of hell
Are you sure the robot was running out of control (non-stop)? It seems to me this code should have the robot not running at all.
Code:
task main()
{

  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;
  wait1Msec(1000);

  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 30; //turn both motors on at 30 percent power
  motor[left] = 30;
   
  motor[right] = 0; //turn both motors off
  motor[left] = 0;

}

What the above code does is to set the motor encoder target to 1 revolution. You then started the motion but immediately you killed the motors by setting them to zero. And then the program ends which would have killed the motors too. What you should have done is to start the motion and wait for it to achieve target before stopping the motors. Something like the following:
Code:
task main()
{

  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;
  wait1Msec(1000);

  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 30; //turn both motors on at 30 percent power
  motor[left] = 30;

  while ((nMotorRunState[right] != runStateIdle) || (nMotorRunState[left] != runStateIdle))
  {
    // do not continue
  }

  motor[right] = 0; //turn both motors off
  motor[left] = 0;

}

Please refer to the RobotC help topics on nMotorEncoderTarget. It has sample code on how to properly use the nMotorEncoderTarget statements. That's the first step of doing PID control on a running robot base. If it is running as expected then you have to worry about how accurate it is and if the robot can run a straight line. There are many topics in the forum about more advanced techniques to deal with these. So focus on getting the above code working first, worry about the rest later.


Thu Dec 26, 2013 10:44 pm
Profile
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post Re: autonomous running like a bat out of hell
I copied your program into mine. When I ran the program, the "tach user" goes to 20,000 and the "tach move" does the same. When the program stops, the "'tach user" will read 200 for a sec then disappear. If I move the wheel by hand It will read perfectly. I have tried every sample program in the book. I have spent Christmas watching tutorials. I have put the encoders on and off several times. I just kicked the robot. Please I need an intervention.
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     arm,           tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     lift,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     right,         tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     left,          tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     tail,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    pick,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    scoopright,           tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    scoopleft,            tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_6,    servo6,               tServoNone)
//*!!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()
{
   servo(scoopleft) = 190;
   servo(scoopright) = 65;                  // Place code here to sinitialize servos to starting positions.
   servo(pick) = 212;

  return;
}

//___________________________________________________________________________________________________________________

task main()
{

  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;

  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 20; //turn both motors on at 30 percent power
  motor[left] = 20;

  while (nMotorRunState[right] != runStateIdle || nMotorRunState[left] != runStateIdle) //while the encoder wheel turns one revolution
  {
    // This condition waits for motors D & E to come to an idle position. Both motors stop
    // and then jumps out of the loop
  }

  motor[right] = 0; //turn both motors off
  motor[left] = 0;

  wait1Msec(3000);  // wait 3 seconds to see feedback on the debugger screens
                    // open the "NXT Devices" window to see the distance the encoder spins.
                    // the robot will come to a stop at the nMotorEncoderTarget position.
}


Fri Dec 27, 2013 3:08 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: autonomous running like a bat out of hell
Let's put some debug code in.
Code:
task main()
{

  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;

  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 20; //turn both motors on at 30 percent power
  motor[left] = 20;

  while (nMotorRunState[right] != runStateIdle || nMotorRunState[left] != runStateIdle) //while the encoder wheel turns one revolution
  {
    nxtDisplayTextLine(1, "EncL=%d", nMotorEncoder[left]);
    nxtDisplayTextLine(2, "EncR=%d", nMotorEncoder[right]);
  }

  motor[right] = 0; //turn both motors off
  motor[left] = 0;

  wait1Msec(3000);  // wait 3 seconds to see feedback on the debugger screens
                    // open the "NXT Devices" window to see the distance the encoder spins.
                    // the robot will come to a stop at the nMotorEncoderTarget position.
}

Make sure you open the "Robot->Debug Windows->NXT remote screen" so you can see the LCD display on your laptop. This will show you what the encoder readings are while it is running.


Fri Dec 27, 2013 5:11 pm
Profile
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post Re: autonomous running like a bat out of hell
copied code to program. added wait for encoders to zero. run program. nxt show negative encoders numbers that go to 47000 then stop. if I change the speed there is no difference. if I put a negative in front of the target encoder numbers, no change. If I put a negative in front of motors, the motors go in reverse and the encoder count is positive. if I take PID off, I can change the speed of the motors. With PID on, I can not change the speed of the motors. When running, I can see a flash of a word on the remote nxt. it is after the right encoder numbers, and says "art" sometimes there is an "st".


Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     arm,           tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     lift,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     right,         tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     left,          tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     tail,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_6,    servo6,               tServoNone)
//*!!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()
{
   servo(scoopleft) = 190;
   servo(scoopright) = 65;                  // Place code here to sinitialize servos to starting positions.
   servo(pick) = 212;

  return;
}*/

//___________________________________________________________________________________________________________________

task main()
{
  nMotorEncoder[right] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[left] = 0;
  wait1Msec(3000);
 
  nMotorEncoderTarget[right] = 1440; //set the target stoping position
  nMotorEncoderTarget[left] = 1440;

  motor[right] = 70; //turn both motors on at 20 percent power
  motor[left] = 70;

  while (nMotorRunState[right] != runStateIdle || nMotorRunState[left] != runStateIdle) //while the encoder wheel turns one revolution
  {
    nxtDisplayTextLine(1, "EncL=%d", nMotorEncoder[right]);
    nxtDisplayTextLine(2, "EncR=%d", nMotorEncoder[left]);
  }

  motor[right] = 0; //turn both motors off
  motor[left] = 0;

  wait1Msec(3000);  // wait 3 seconds to see feedback on the debugger screens
                    // open the "NXT Devices" window to see the distance the encoder spins.
}                    // the robot will come to a stop at the nMotorEncoderTarget position.


Tue Dec 31, 2013 1:34 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: autonomous running like a bat out of hell
sprtmed wrote:
copied code to program. added wait for encoders to zero. run program. nxt show negative encoders numbers that go to 47000 then stop. if I change the speed there is no difference. if I put a negative in front of the target encoder numbers, no change. If I put a negative in front of motors, the motors go in reverse and the encoder count is positive. if I take PID off, I can change the speed of the motors. With PID on, I can not change the speed of the motors. When running, I can see a flash of a word on the remote nxt. it is after the right encoder numbers, and says "art" sometimes there is an "st".

If you set the motor a positive value and the encoder was going negative, you may want to check the wiring of the motor. Make sure the positive terminal of the motor (red wire) is actually wired to the + terminal on the motor controller. That's the only thing I can think of that will give you that behavior.


Thu Jan 02, 2014 4:39 am
Profile
Rookie

Joined: Thu Dec 26, 2013 8:17 pm
Posts: 9
Post Re: autonomous running like a bat out of hell
Thanks for the help. Everything is hooked up correctly. It is the same problem that has been on the forum before. Very, very, frustrating. Hard to teach kids when you can't explain the problem. Guess I will go back to timed tasks.


Fri Jan 03, 2014 10:28 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.