View unanswered posts | View active topics It is currently Tue Sep 23, 2014 12:32 am






Reply to topic  [ 8 posts ] 
Read servo position with MindStorms? 
Author Message
Rookie

Joined: Tue Mar 13, 2012 1:18 am
Posts: 8
Post Read servo position with MindStorms?
Hi there,

Very new to MindStorms, tho I've coded up AVRs and microcontrollers...
Question- For the NXT servo motors, can I read the current position? To clarify, there could be an obstruction that makes the motor move less than it's been told. My goal is to use it to aid in detecting whether an object is gripped.

I read that the NXT servos have tachometers built in.


Tue Mar 13, 2012 1:25 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Read servo position with MindStorms?
Hi cyman,

You read correctly. You can easily read the current tacho count with:
Code:
task main ()
{
  long YoQuieroTachoBell = 0;
  while(true)
  {
    YoQuieroTachoBell = nMotorEncoder[motorA];
    nxtDisplayTextLine(2, "%d", YoQuieroTachoBell);
    wait1Msec(100);
  }
}

You can reset the count simply by assigning 0 to nMotorEncoder, like this:
Code:
nMotorEncoder[motorA] = 0;

- 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]


Tue Mar 13, 2012 3:02 am
Profile WWW
Rookie

Joined: Fri Jan 27, 2012 6:57 pm
Posts: 40
Post Re: Read servo position with MindStorms?
Quote:
long YoQuieroTachoBell = 0;

You're hilarious, Xander :lol:


Wed Mar 14, 2012 1:45 am
Profile
Rookie

Joined: Tue Mar 13, 2012 1:18 am
Posts: 8
Post Re: Read servo position with MindStorms?
Thanks! Also, one big issue is setting the motor to an absolute position. Can i do that?
For example, I have a hand that i want to open and close, but i need the motors to be in the right initial position for it to work. in practice, when i start my robot, the motored hand is typically semi open or semi closed, forcing me to physically calibrate it.. A big pain.

Ive used servo controllers like the ssc32 that will let you set an absolute position. Wondering if thats possible.


Thu Mar 22, 2012 3:42 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Read servo position with MindStorms?
Nope, you 'll need some other way to calibrate the starting position. Perhaps something like a button that's pressed when the hand is at the the limit of it's movement. For absolute position, you need something like a potentiometer.

_________________
sudo rm -rf /


Last edited by magicode on Fri Mar 23, 2012 12:45 am, edited 1 time in total.



Thu Mar 22, 2012 8:40 am
Profile
Rookie

Joined: Tue Mar 13, 2012 1:18 am
Posts: 8
Post Re: Read servo position with MindStorms?
ok thanks!


Thu Mar 22, 2012 9:11 pm
Profile
Expert

Joined: Wed Jun 30, 2010 7:15 am
Posts: 181
Post Re: Read servo position with MindStorms?
A button could work, but that would cost you a sensor port; you could also do something like this
Code:
motor[motorA] = 10;
while(motorPWMLevel[motorA] > 25){}
motor[motorA] = 0;
nMotorEncoder[motorA] = 0;
That would make it go backwards until it's detected that it has hit something and can't move any further. That would only work if, again, the motor can't physically move past one point like magicode said.

Another option is the HiTechnic Angle Sensor which will keep track of the angle of the motor even if the robot has been turned off:

http://www.hitechnic.com/cgi-bin/commer ... ey=NAA1030

_________________
leonoverweel.com


Thu Mar 22, 2012 9:29 pm
Profile WWW
Rookie

Joined: Tue Mar 13, 2012 1:18 am
Posts: 8
Post Re: Read servo position with MindStorms?
Hi dimastero.... Thanks thats handy and will work in my situation!


Fri Mar 23, 2012 1:53 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.