ROBOTC.net forums
http://www.robotc.net/forums/

nMotorEncoder reset
http://www.robotc.net/forums/viewtopic.php?f=1&t=1769
Page 1 of 1

Author:  todorangrg [ Thu Jul 23, 2009 3:46 pm ]
Post subject:  nMotorEncoder reset

Hello,
I realised during my testing that the nMotorEncoder resets after the nMotorEncoderTarget command. My project requires a nMotorEncoder that never resets(unless I tell so). Can I do something about that?I tried to find the function in the include files to modify it but with no success. What I am needing is like "total tach" from the debugger window.
So far I built a task that keeps the count but in fast oscilative movements(with other tasks working) it skips some ticks :( .
Any help would be highly apreciated.

Best Regards,
George T.

Author:  Jeff McBride [ Thu Jul 23, 2009 6:41 pm ]
Post subject:  Re: nMotorEncoder reset

The solution is to not use the nMotorEncoderTarget feature and do the tests yourself. I suggest creating your own array of target values and having a separate task that loops forever checking the position of each encoder and stopping any motor(s) that have met or exceeded their target. That way you can use it just like the built in behavior but without the reset feature. You will need to think about how to deal with the counters wrapping and other similar boundry conditions.

Author:  todorangrg [ Fri Jul 24, 2009 2:41 am ]
Post subject:  Re: nMotorEncoder reset

I understand what you say but nMotorEncoderTarget is very good because it has that slow-to-stop movement that skips in the worst case 1 tick. That is why I tried to change the nMotorEncoder.But how does nMotorEncoderTarget slows?that´s why I asked for the include.Is it using PID based algorithm?

Best Regards,
George T.

Author:  Jeff McBride [ Fri Jul 24, 2009 12:22 pm ]
Post subject:  Re: nMotorEncoder reset

I don't know for sure what method it is using but I would guess that it uses PID. Are you using standard LEGO motors? The code for Tetrix motors is likely to be quite different since the encoders have about 10x the resolution of the LEGO motors.

Author:  todorangrg [ Fri Jul 24, 2009 1:29 pm ]
Post subject:  Re: nMotorEncoder reset

I am using standard Lego motors. But one question still remains: Where is the file with the code of the nMotorEncoderTarget and nMotorEncoder?

Best Regards,
George T.

Author:  Ford Prefect [ Fri Jul 24, 2009 1:38 pm ]
Post subject:  Re: nMotorEncoder reset

there is no certain file. It's a hidden obscured undocumented function, certainly a feature, not a bug ;)

Author:  todorangrg [ Fri Jul 24, 2009 1:43 pm ]
Post subject:  Re: nMotorEncoder reset

:lol: Sarcastic as usual...

Author:  todorangrg [ Thu Jul 30, 2009 1:43 pm ]
Post subject:  Re: nMotorEncoder reset

well I've built a PD algorithm that works theoretically. But when I try to add the Integral part everyting goes messy(the motor runs endlessly). I used the constants that were apearing in the robotc debugging window(450,50,650) and divided the whole PID ecuation by 100. Are these the correct constants that the nMotorEncoderTarget is using? If not I haven't found a good way of finding them. Trial and error sounds a bit to time consuming so if anyone knows a theoretical way of finding them(or a more theoretical trial and error) it would be really apreciated. I read about the Ziegler–Nichols algorithm but calculating the oscilation period of the motor is quite triky because it oscilates very fast. All in all this is what I wrote so far:

Code:
Void nMotorEncodeTargetNoReset(tMotor link, int nTargetNew){
  int nDtargetOld,nDtargetNew,nValue;
  float fIntegral;
  const float Kp=i will have to find out
  const float ki -//-
  const float kd -//-

  nDTargetOld=nTargetNew-nMotorEncoder[link];
  do {
    nDtargetnew=ntargetnew-nMotorEncoder[link];
    fintegral=fintegral+nDtargetnew;
    fValue=nDtargetNew*kp+integral*ki+(nDtargetNew-nDtargetOld)*kd;
    if (fValue>100)
       motor[link]=100;
    else if (fValue<-100)
       motor[link]=-100;
    else
       motor[link]=fValue;
    nDTargeOld=nDTargetNew;
  }while(nMotorRunState!=Run_State_idle);


There may be some syntax errors because I worte it from my rememberings(i don't have my laptop with my files right now).

EDITED by Miki to add code tags around code section

Author:  miki [ Thu Apr 26, 2012 4:39 am ]
Post subject:  Re: nMotorEncoder reset

todorangrg wrote:
Where is the file with the code of the nMotorEncoderTarget and nMotorEncoder?
Hi todorangrg,
I would say this code is part of the firmware released with RobotC and can't be find (as source code) in programs running over it.
Miki.

Author:  NeXT-Generation [ Fri Apr 27, 2012 10:09 pm ]
Post subject:  Re: nMotorEncoder reset

Um, not to be rude Miki, but why did you revive a thread of 3-years age?

Author:  miki [ Sat Apr 28, 2012 5:07 am ]
Post subject:  Re: nMotorEncoder reset

well :roll: just after I rescued my PC, I tested it a bit to check if everything was ok. I went on RobotC forum and answered to this new topic.
then I updated the PC clock :? :mrgreen:

Miki.

Author:  magicode [ Sat Apr 28, 2012 8:24 am ]
Post subject:  Re: nMotorEncoder reset

Aha, I was wondering about that. I was curious that I'd never seen this thread before, and then I noticed Ford Perfect had posted, and after much surprise, I noticed the date. Does phpBB really work off of your system time? :shock:

Author:  miki [ Sat Apr 28, 2012 10:41 am ]
Post subject:  Re: nMotorEncoder reset

Hum. you may be right. :wink: The fact my PC believed we were in 2002 doesn't explain anything. It is possible that I saw a new post (the one stamped April 24th, 2012, 12:41 pm) of todorangrg and then I navigate in his posts without paying attention to their date. :roll:


April 24th, 2012, 12:41 pm

Author:  NeXT-Generation [ Sat Apr 28, 2012 10:53 am ]
Post subject:  Re: nMotorEncoder reset

miki wrote:
Hum. you may be right. :wink: The fact my PC believed we were in 2002 doesn't explain anything. It is possible that I saw a new post (the one stamped April 24th, 2012, 12:41 pm) of todorangrg and then I navigate in his posts without paying attention to their date. :roll:


April 24th, 2012, 12:41 pm


I hereby award you the prize for longest unintended thread bump in history!!!!!

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/