View unanswered posts | View active topics It is currently Thu Oct 02, 2014 10:28 am






Reply to topic  [ 5 posts ] 
Drive motors with PID turn right 
Author Message
Rookie
User avatar

Joined: Wed Dec 11, 2013 6:11 pm
Posts: 2
Location: Tulsa, OK
Post Drive motors with PID turn right
We have a drive setup with a DC Motor for the left wheels and a DC Motor for the right wheels. Everything works fine until PID is switched on for those motors, then when driving forward, the robot pulls a long, slow right turn. It comes down to the fact that we need nMotorEncoderTarget to work, but that will not function without PID on. The robot drives as straight as an arrow with PID turned off. I turn to you all for your wisdom in this matter.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     rightwheels,   tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     leftwheels,    tmotorTetrix, PIDControl, encoder)

task main()
{
  //nMotorPIDSpeedCtrl[rightwheels] = mtrNoReg; // trying this killed nMotorEncoderTarget, but made the robot drive straight.
  //nMotorPIDSpeedCtrl[leftwheels] = mtrNoReg;

  nMotorEncoder[rightwheels] = 0;  //clear the TETRIX motor encoders
  nMotorEncoder[leftwheels] = 0;

  wait1Msec(100);

   nMotorEncoderTarget[rightwheels] = 25000;
   nMotorEncoderTarget[leftwheels] = 25000;

   motor[rightwheels] = -50;  // Move motors at 50% power
   motor[leftwheels] = -50;

  while(nMotorRunState[rightwheels] != runStateIdle && nMotorRunState[leftwheels] != runStateIdle)
   {
     // Do not continue.
   }

  // Stop Forward Drive
  motor[rightwheels] = 0;
  motor[leftwheels] = 0;
}

_________________
Scott Smith
FTC Team 5695
The Fellowship


Wed Dec 11, 2013 6:28 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Drive motors with PID turn right
There are PID control topics on the RobotC curriculum.
http://www.education.rec.ri.cmu.edu/pre ... dex.htm#15

For your purpose, you should watch the "Movement/Improved Movement" section especially on PID control and synchronize motors.


Wed Dec 11, 2013 7:26 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Drive motors with PID turn right
Sorry, I forgot that Sync motors only works for Lego motors. It doesn't work for Tetrix motors. If you really want to go straight, you may want to do your own PID control such as:
http://www.robotc.net/forums/viewtopic. ... 579#p27579

BTW, remember to disable built-in PID if you are doing your own PID control.


Wed Dec 11, 2013 7:35 pm
Profile
Rookie
User avatar

Joined: Wed Dec 11, 2013 6:11 pm
Posts: 2
Location: Tulsa, OK
Post Re: Drive motors with PID turn right
Well the whole point of using PID was so nMotorEncoderTarget works. I don't care to have it on otherwise. Also, this clearly isn't standard behavior for these motors so either RobotC's screwed or it's an issue with our robot.

_________________
Scott Smith
FTC Team 5695
The Fellowship


Wed Dec 11, 2013 7:38 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Drive motors with PID turn right
As you can see in the PID control video, it is not uncommon that the robot will run drifted to the left or right because PID control on individual motors will achieve target independently but not necessarily in sync. Tetrix motors are notoriously inconsistent from motor to motor. So you need to compensate it in software. The sync motor function for the Lego motors has the right idea. Unfortunately, it was not implemented to support Tetrix. But it is not really that difficult to implement the compensation yourself.


Wed Dec 11, 2013 7:45 pm
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.