View unanswered posts | View active topics It is currently Wed Oct 22, 2014 3:20 am






Reply to topic  [ 5 posts ] 
Problem setting motor encoder 
Author Message
Rookie

Joined: Fri Feb 16, 2007 4:11 pm
Posts: 41
Location: Padanaram, MA
Post Problem setting motor encoder
Greetings all,

I am unable to set the motor encoder to the value I desire. I want to set it in the middle of its range of possible values (<= 0 <= 32768) so that I won't have to contend with negative encoder values, which release the brakes. Here is some simple code to see the problem:

:shock: #pragma config(Motor, motorA, motor_A, tmotorNormal, PIDControl)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int motorEncoderValue;

task main()
{
nMotorPIDSpeedCtrl[motorA] = mtrSpeedReg; // Enable motor-speed regulation
bFloatDuringInactiveMotorPWM = false; // Brakes on
nMotorEncoder[motorA] = 16384; // Initial encoder value
motorEncoderValue = nMotorEncoder[motorA]; // Current value of motor encoder
}

When I use the debugger to single step through this with the Global Variables window open, I get motorEncoderValue = 0 even though I have set the motor encoder value to 16384, in the middle of the range of possible values.

I am using Robot C Ver. 1.45.

Has anyone any ideas about what is wrong?

Regards,

Ted


Fri Nov 21, 2008 4:33 pm
Profile WWW
Novice

Joined: Sun Feb 04, 2007 12:48 am
Posts: 69
Location: Australia
Post Re: Problem setting motor encoder
Hi Ted,

I may be wrong but I didn't think you could set the nMotorEncoder value.
Quote:
nMotorEncoder[motorA] = 16384; // Initial encoder value

Instead you can read it. ie While encoder is < 16384 do x;

All you can do is reset the encoder to 0.

I think this is correct, but not 100%
Code:
Also, please post any code inside these type of boxes
If you haven't seen the buttons, just above the text box where you typed your message, manually type "[code]" before "[/code]" after your code.


Sat Nov 22, 2008 2:12 am
Profile
Rookie

Joined: Fri Feb 16, 2007 4:11 pm
Posts: 41
Location: Padanaram, MA
Post Re: Problem setting motor encoder
I think you might be right! The Motor help screen says: "nMotorEncoder[]/ Read/write the current position of a motor encoder." The only value you can write is apparently zero! That's unfortunate. Perhaps this can be modified to enable writing values other than zero to the encoder. That would be very useful.

Thank you for enlightening me.

Ted


Sat Nov 22, 2008 12:06 pm
Profile WWW
Rookie

Joined: Sat Nov 29, 2008 4:21 am
Posts: 4
Post Re: Problem setting motor encoder
I don't think that this line:
Quote:
nMotorPIDSpeedCtrl[motorA] = mtrSpeedReg; // Enable motor-speed regulation

Is needed, The #pragma statement that the compiler generates when you use the motor/sensor setup window includes activating PID control.
The only reason that command could be useful is if you have a motor that mid program you want to turn PID control on/off. We even run our robot without PID control at all because we only use one encoder on the drive wheels, with a compass for turning.

_________________
Ian McBride
Benson Robotics Club


Sat Nov 29, 2008 4:28 am
Profile
Rookie

Joined: Sun Nov 09, 2008 3:29 am
Posts: 3
Post Re: Problem setting motor encoder
I hate this bug. Even with no PID speed control settings, writing to the encoders doesn't work, only changes to zero. :programmer: :D :programmer: :( :x :evil: :breakcomputer:

here is the code I am trying:

Code:
task main()
{

     nMotorEncoder[motorB]=0;            //reset motor encoder
         
     while(1){                         
    
          if(nMotorEncoder[motorB]>=1000){      //resrict encoder to below1001
               nMotorEncoder[motorB]=1000;
          }
    
          if(nMotorEncoder[motorB]<-1000){       //resrtict encoder to above -1001
               nMotorEncoder[motorB]=-1000
          }

     motor[motorA]=(nMotorEncoder[motorB])/10;       //run motor a based on motor b's encoder
  }
}

i am making a mixer that can be acuratley controlled by another motor via rotation (encoder) sensor. I want to be able to stop the motor easily if i turn the motor way past the maximum motor power. I hate that assigning a number to a motor encoder resets it!!!!! :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer: :breakcomputer:
writing to a motor encoder works on older versions (i am using 1.47 beta (http://www.robotc.net/downloads/ROBOTCforMindstorms_147_BETA.exe)). I have tried this with all betas from 1.40 and up. doesn't work. i remember version 1.0 did (came on CD).


Thu Jan 01, 2009 11:48 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.