|
cdasher
Rookie
Joined: Thu Jan 21, 2010 3:08 pm Posts: 2
|
 Tetrix motor PID controls?
I want to be able to determine how far my robot goes based on the PID control in the tetrix motors. Is this like the NXT motor, where it polls how many degrees of rotation the motor has gone? Is this possible, and if so, what is wrong with my code?
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none) #pragma config(Sensor, S2, ultra, sensorSONAR) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C3_1, motorF, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C3_2, motorG, tmotorNormal, PIDControl, encoder) #pragma config(Servo, srvo_S1_C2_1, , tServoNormal) #include "JoystickDriver.c"
void initializeRobot() { servo[servo1] = 80; return; }
void move (int x, int y); void move (int x, int y) { int target1; target1 = x * 360 / 12.56; nMotorEncoder[motorF] = 0; nMotorEncoderTarget[motorF] = target1; motor[motorF] = -y; int target2; target2 = x * 360 / 12.56; nMotorEncoder[motorG] = 0; nMotorEncoderTarget[motorG] = -target2; motor[motorG] = y; }
task main() { initializeRobot();
while (true) { move (20,-100); } }
|
|
SSI
Rookie
Joined: Mon Feb 23, 2009 12:40 pm Posts: 27
|
 Re: Tetrix motor PID controls?
One problem I see is that you have 360 as the number of counts per revolution. Actually the encoders have 1440 counts per revolution. I am not sure about using nMoterEncoderTarget with the 12VDC motors (our programmer just calculated the count value and waited until they were reached and stopped the motors.
Also, the way your code is written, your move routine is called every time through the main loop. You may want to wait in your routing until the robot has finished moving and you probably don't want to call you routine every time through the main while loop.
|