1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

[NXC]TachoCount problem

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.

[NXC]TachoCount problem

Postby matzzn » 21 Feb 2013, 17:50

I'm just trying to wirte a function for fast motor-movements.
I have a problem with "GetOutput( OUT_A, TachoCount);"
After resetting the TachoCount, GetOutput returning not 0.

Code: Select all

inline void RunMotor ( byte out, char pwr, long angle)
{
   long tacho;
   long pre_tacho;
   unsigned int stady_state;
   int i;

   ResetTachoCount(OUT_A);
   SetMotorRegulationTime (10);
   
   if (angle < 0)
   {
      pwr = -pwr;
   }
   OnFwd (out, pwr);
   
   do
   {
      i++;
      tacho = GetOutput( out, TachoCount);
      if (tacho == pre_tacho) {stady_state++;}

      if ( i%50 == 0) {pre_tacho = tacho;}  // lower the resolution

   } while (tacho < angle &&  !(stady_state > (angle *100 / pwr) ) );

   OffEx (out, RESET_ALL);  // i think off  causes the problem
   Yield();
}
   

task main ()
{
   long tacho;

   RunMotor (OUT_A, 100, 90);

   Wait (1000);
   
   // Lets reset TachoCount so it should be 0
   ResetTachoCount(OUT_A);
   
   tacho = GetOutput( OUT_A, TachoCount);
   
   // tacho != 0 , tacho = 50!!!   << whats wrong?
   NumOut(5, LCD_LINE1, tacho);
   
   Wait(5000);
}

matzzn
 
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]TachoCount problem

Postby doc-helmut » 21 Feb 2013, 19:01

hey,
no solotution to your problem - but a hint:
to my experience, all my NXC code with functions using TachoCount are causing REAL BIG CRA.... aaahm: MISTAKES ;)

The fw seems to use this for obscured internal purposes.

IMHO, maybe you better wish to try RotationCount instead!
regards,
HaWe
±≠≈αγδεωΔΦΣ∫√∅∞
NXC CHESS for NXT: http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
indispensable for NXC + EV3-C: easy + trouble-free network & sensor+motor remote control for rs485, BT, USB!
User avatar
doc-helmut
 
Posts: 2424
Joined: 29 Sep 2010, 14:25

Re: [NXC]TachoCount problem

Postby matzzn » 21 Feb 2013, 20:11

The fw seems to use this for obscured internal purposes.


That was my first thought (I think OffEx() )
RotationCount causes this problem also.
matzzn
 
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]TachoCount problem

Postby afanofosc » 22 Feb 2013, 01:16

After issuing a command to set an output module IOMap field you have to wait at least one millisecond before the output module will actually read the value you set in the IOMap and do something about it (i.e., reset the tacho or block tacho or rotation count). So

Code: Select all
   // Lets reset TachoCount so it should be 0
   ResetTachoCount(OUT_A);
   Wait(MS_1); // wait for Output module to actually reset the tacho count
   tacho = GetOutput( OUT_A, TachoCount);
   


However, as documented and as suggested by Doc, you should never use the Tacho count in your own code since it is used by the firmware internally. Use instead the RotationCount which is not used at all by the firmware.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

Re: [NXC]TachoCount problem

Postby matzzn » 22 Feb 2013, 08:02

Thanks seems fixed now. That's a really tricky bug ;)
I'm going to change everything to "Rotation Count".
matzzn
 
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]TachoCount problem

Postby matzzn » 22 Feb 2013, 08:17

Ok next problem.

Code: Select all

   ...
   } while (tacho < angle &&  !(stady_state > (angle *100 / pwr) ) );

   Off (out);
   
   /*This solves the problem
   Wait(200);
   Coast(out);
   */
   
   Wait(1);
   ResetRotationCount(OUT_A);
   Wait(1);
}

....

   RunMotor (OUT_A, 100, 90);
   Wait (1000);
   tacho = GetOutput( OUT_A, RotationCount);
   // tacho != 0 , tacho = 50!!!   << whats wrong?
   NumOut(5, LCD_LINE1, tacho);




If I put a wait after RunMotor I get again wrong values.
matzzn
 
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]TachoCount problem

Postby doc-helmut » 22 Feb 2013, 10:15

just a guess -
what, if you changed "inline void RunMotor()" into
"safecall void RunMotor()"
?

maybe you wish to post the whole source code again?
regards,
HaWe
±≠≈αγδεωΔΦΣ∫√∅∞
NXC CHESS for NXT: http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
indispensable for NXC + EV3-C: easy + trouble-free network & sensor+motor remote control for rs485, BT, USB!
User avatar
doc-helmut
 
Posts: 2424
Joined: 29 Sep 2010, 14:25

Re: [NXC]TachoCount problem

Postby afanofosc » 22 Feb 2013, 19:59

I do not think you need to change inline to safecall as Doc suggests you try.

Instead, I think that RunMotor is no longer resetting all the counters at the end of the function call. But why should it anyway? It seems best to explicitly reset the rotation counter outside of a generic motor rotation function, unless you can pass in a parameter saying whether to reset or not. And it is best to not reset the internal counters if you don't need to.

Just call ResetRotationCount(OUT_A); Wait(MS_1); after RunMotor() and then your rotation counter will be zero when you read it next with MotorRotationCount(OUT_A);

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN


Return to Mindstorms Software

Who is online

Users browsing this forum: No registered users and 0 guests