View unanswered posts | View active topics It is currently Fri Jul 25, 2014 10:31 am






Reply to topic  [ 2 posts ] 
nMotorEncoder[] write clarification 
Author Message
Rookie

Joined: Fri Mar 02, 2007 11:41 pm
Posts: 5
Location: Pennsylvania
Post nMotorEncoder[] write clarification
Hi,

It was my understanding that the nMotorEncoder[] could be written to in order to pre-set the value of the encoder. This is important because I built a circuit to swap between two different motors that share the same port. I would like to be able to read the value of the motor encoder right before the swap, store it in an array, then track the second motor's progress using the encoder. When it is about to swap back, it stores the latest encoder position to a second array element and RE-Initializes the nMotorEncoder with the first motors last position prior to the first swap. (This way neither motor looses the last known position of it's encoder.) I have all of the code written and the circuit built, but I can't seem to get the nMotorEncoder[] to re-Initialize to the stored value.
For example:
Code:
nMotorEncoder[motorA] = previousEncoderValue;


Should this be able to function with this code? Is there another way to assign the Encoder a value from a variable?

Any help would be much appreciated.

Thank you.
Mark


Sat May 05, 2007 5:28 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
There is a "write" function for motor encoders. But it is really a "reset to zero" function -- it sets the motor encoder value to zero regardless of the value that you try to write to it.

This is not that unusual behavior. Many microprocessors have a "write" function that is used to "reset to zero" an I/O line.

Since you're going to be using custom code for your dual motors on one port, you can write a simple function that will give you the encoder delta for each of your two motors. You'll need to keep track of "my cumulative encoder" and "current start position".

Every time you switch motors you first add the value of "current encoder" - "start positon" to "my cumulative encoder" for the motor that was moving. Then you set "start position to "current encoder".

When you want to get the encoder position for the current motor you add "my cumulative encoder" with "current encoder" - "start position".


Sun May 06, 2007 11:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.