Recommended Posts

Hi all!

I'm programming a robot that has limited travel on one of its articulations. I don't require precision on its position, just that it stops the motor as soon as it hits the limit.

NXC has the MotorOverLoad function, which appears to do exactly what I want... however, it always returns "false" even if the motor is completely stalled! Digging a bit, I found that MotorOverload is actually a shortcut for one of the fields of GetOutput (like "GetOutput(OUT_A, OverloadField)"). Checking the field's documentation, I see that, for it to work, I need to set the motor according to numerous parametres... but, after setting them, I can't get the motor to actually run!

This is what I wrote to get the motor running, while enabling MotorOverload:

SetOutput(
 OUT_C,
 RunStateField, OUT_RUNSTATE_RUNNING,
 OutputModeField, OUT_MODE_MOTORON + OUT_MODE_REGULATED,
 RegModeField, OUT_REGMODE_SPEED,
 PowerField, power_C * d);

(power_C and d are variables I defined)

If I use the normal "OnFwd" instead, the motor is never stopped:

if(MotorOverload(OUT_C))
{
 Stop(OUT_C);
}

What could I be doing wrong? Thanks in advance!

Share this post


Link to post
Share on other sites

If I could suggest anything, I'd recommend you to raise this question at the MindBoards Forums, where you may get the support from the most prominent specialists in the field and even the authors of NXC.

Share this post


Link to post
Share on other sites

Couldn't you just use an "IF" command instead?

Like:

if motorlimit = true;
motor = 0;
else;
motor = 100;
end_if;

Edited by Carsten Svendsen

Share this post


Link to post
Share on other sites

What language did you use for that code? It doesn't have the structure of NXC, and I couldn't find any NXC function named "motorlimit".

Share this post


Link to post
Share on other sites

What language did you use for that code? It doesn't have the structure of NXC, and I couldn't find any NXC function named "motorlimit".

I think he is using pseudo code, not an actual language.

But you are using an If statement, so I am not sure what he means either.

Share this post


Link to post
Share on other sites

It was just an example for the simple and very basic "IF" command :wink:

You'd have to replace the condition for if to be true or false depending on the way you program it

Share this post


Link to post
Share on other sites

That's what he is doing, but the MotorOverload always returns false.

Share this post


Link to post
Share on other sites

Yes, that's what I'm doing. The problem is that, if I use the first piece of code instead of the normal "OnFwd", the motor doesn't start... if I do use "OnFwd" and the second piece of code, the motor doesn't stop.

Anyway, I followed Conchas' suggestion and posted the question at Mindboards.

Share this post


Link to post
Share on other sites

Oh ok, sorry for the inconvenience

No problem. You were just trying to help :thumbup:

Share this post


Link to post
Share on other sites

the trick to this is to monitor the rotation count of the output in a timed interval, if the rotation count is zero or a very low number you know the outpout is not rotating, i.e. its stalled.

Share this post


Link to post
Share on other sites

the trick to this is to monitor the rotation count of the output in a timed interval, if the rotation count is zero or a very low number you know the outpout is not rotating, i.e. its stalled.

Indeed. But shouldn't the MotorOverload method do this for you?

Share this post


Link to post
Share on other sites

I got the solution! My problem was that I was missing the update flags on SetOutput, which commit the changes. By using OnFwdReg, all required parametres were set automatically. Here is John Hansen's explanation.

Anyway, I found out by experimentation that MotorOverload takes a while to conclude that the motor is stalled (it increases the motor power to try to overcome the limit until it gives up), so I checked instead if MotorActualSpeed (the power applied to the motor) was greater than 75%, and it worked.

if(abs(MotorActualSpeed(OUT_C)) > 75)
{
Off(OUT_C);
stall_C = sign(MotorActualSpeed(OUT_C)); //Won't try moving in this direction next time
}

kieran, there's no need to manually do that: that's (if I'm not mistaken) the purpose of the MotorTurnRatio function. ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.