Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: DC MotorEncoder Code (http://www.chiefdelphi.com/forums/showthread.php?t=90759)

JohnFogarty 02-02-2011 11:34

[FTC]: DC MotorEncoder Code
 
So in the instance of having servos, those servos have set positions you can send them to. What I want to do is tell a motor to go to specific encoder positions in robotC. I haven't the slightest clue how to begin doing that. My goal is to push a button and have an arm powered by a motor go to a certain position and stop or keep a low level of power to keep it locked in that position until the button isn't pressed.
Thank You.
John Fogarty

normalmutant 02-02-2011 19:15

Re: [FTC]: DC MotorEncoder Code
 
Here's one way to do it:
Have the motor move back until it hits a touch sensor. Set the input from the encoder as the zero position (store it in a variable) and move the motor forward to the encoder position you want, plus the zero value.
We did this to align a dispenser tread on our old robot. If it doesn't rotate all the way around, you may not have to do this.

normalmutant 02-02-2011 21:43

Re: [FTC]: DC MotorEncoder Code
 
Oh, actually, you could just reset the encoder using the software when it hits the touch sensor. Sorry, I'm a hardware guy. I was unsure about my last post, so I read our team's own tutorial on using them. :p
http://say-watt.org/wp2/archives/391

Tim Delles 04-02-2011 02:42

Re: [FTC]: DC MotorEncoder Code
 
Code:

nMotorEncoder[motorA] = 0;
wait1Msec(50);
nMotorEncoderTarget[motorA] = x;    <- set this to the number of rotations the Motor Encoder needs to rotate
motor[motorA] = 100;
while ((nMotorRunState[leftMotor] != runStateIdle))
  {
    EndTimeSlice();
  }
  return;

This can only be used if you have a shaft encoder attached to the motor you want to use. Good luck.

clwillingham 04-02-2011 14:54

Re: [FTC]: DC MotorEncoder Code
 
another way thats a bit more direct but probably a little bit less reliable in terms of skidding:

Code:

motor[FL] = power;
motor[FR] = power;
motor[BL] = power;
motor[BR] = power;
while(nMotorEncoder[FL] < units){}
Stop(); // we wrote this function to set every motor to 0.

please note that this code is for a four wheel drive robot.


All times are GMT -5. The time now is 19:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi