View unanswered posts | View active topics It is currently Thu Aug 21, 2014 12:38 pm






Reply to topic  [ 3 posts ] 
Finding the speed of a motor? 
Author Message
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Finding the speed of a motor?
Hello,

I am wanting to work out the speed of the motor, so that when it is slowed down, such as when the robot is pushing somthing, I can have the program do somthing. But I can't seem to get the motor values.

In the program below, it is supposed to show the value of nMotorEncoder of motor A on the screen, but this shows 0 or -1, which is unhelpful. I'm expecting to see a range of numbers between -32768 and 32767

Any ideas?
Thanks
Karl

Code:
#pragma config(Sensor, S1,     Touch1,              sensorTouch)
#pragma config(Motor,  motorA,          MotorA,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int bToggle = 0;
int motorPos = 0;
// move the motor until it is stopped.
void valveOn(short MotorX, int Direction)
{
 
  if (Direction == 1) {
    motor[motorA] = 80; 
  }
  else {
    motor[motorA] = -80;   
  }

}

task motorSpeed() {
 
  while (true) {
    motorPos = nMotorEncoder[MotorA];
    nxtDisplayBigStringAt (0,60,"P1: %d  ", motorPos);
    wait1Msec(500);
  }
}

task main() {
 
    // setup motor stuff
  nPowerDownDelayMinutes  = 240;  // 4 hours
  bNoPowerDownOnACAdaptor = true;
  nMotorPIDSpeedCtrl[MotorA] = mtrSpeedReg;
 
  StartTask(motorSpeed);
 
  while (nNxtButtonPressed != 3) {
   
    if (SensorValue(Touch1) == 1) {
      bToggle = 1;
    }
    else {
      bToggle = 0; 
    }
   
    valveOn(MotorA, bToggle);
    wait1Msec(200);
  }
}


Tue Nov 08, 2011 6:44 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3188
Location: Rotterdam, The Netherlands
Post Re: Finding the speed of a motor?
Actually, the encoders are signed longs, so that would make it range from about -2147483648 to 2147483647 or thereabouts. Ensure your motorPos variable is properly sized.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Nov 09, 2011 2:39 am
Profile WWW
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Re: Finding the speed of a motor?
OK. Thanks.


Sun Nov 13, 2011 11:40 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.