Motor Issue and NXC
-
- Posts: 346
- Joined: 27 Sep 2010, 03:05
- Contact:
Motor Issue and NXC
I'm having a problem with the LEGO motors and the standard firmware, and I'm hoping to find a solution using NXC.
First, I have a robot with 2 motors, and I want it to spin in place (one motor forward, one backward). This turn needs to be as accurate as the software will allow.
Using:
RotateMotorEx(OUT_BC, 50, 400, 100, true, true); // port, power, distance, turn, sync, stop
... it seems to work well (50% power), with both motors traveling 400 degrees. However, when I change the power to 75, the motor moving in reverse only seems to go about 350 degrees, while the forward motor still goes 400. And, when I change the power to 100, the reverse motor drops down under 300 degrees.
From what I can tell, this is a firmware issue, and NOT an NXC issue. A program in NXT-G seems to act the same way.
So, I'm looking for the set of motor commands that will:
A) Set motor B forward 75%
B) Set motor C backward 75%
C) Set the limit on both motors to 400
D) Run the motors at the same time, until they reach their limit, then hold position.
I'm not too worried about the motors being synchronized, as long as they run the right distance, and stop.
I've been messing around for far too long trying to find out the right combination of commands, so if anyone could help, that would be good.
Thanks
Steve
First, I have a robot with 2 motors, and I want it to spin in place (one motor forward, one backward). This turn needs to be as accurate as the software will allow.
Using:
RotateMotorEx(OUT_BC, 50, 400, 100, true, true); // port, power, distance, turn, sync, stop
... it seems to work well (50% power), with both motors traveling 400 degrees. However, when I change the power to 75, the motor moving in reverse only seems to go about 350 degrees, while the forward motor still goes 400. And, when I change the power to 100, the reverse motor drops down under 300 degrees.
From what I can tell, this is a firmware issue, and NOT an NXC issue. A program in NXT-G seems to act the same way.
So, I'm looking for the set of motor commands that will:
A) Set motor B forward 75%
B) Set motor C backward 75%
C) Set the limit on both motors to 400
D) Run the motors at the same time, until they reach their limit, then hold position.
I'm not too worried about the motors being synchronized, as long as they run the right distance, and stop.
I've been messing around for far too long trying to find out the right combination of commands, so if anyone could help, that would be good.
Thanks
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
Re: Motor Issue and NXC
By no means an expert on Lego so can't help with the commands but I can say that I have seen complaints about similar problem before whilst trawling the web trying to get information.
Here is a link to tests carried out on older Lego motors but it might also apply to the later models.
http://www.sjbaker.org/steve/lego/motor_speed.html
If it does then presumably the question is whether the command you are using will cease when either of the rotation counters reaches the specified limit. If that is the case then both motors will stop, even if one is lagging. Could be that you would have to issue separate commands for each motor.
Here is a link to tests carried out on older Lego motors but it might also apply to the later models.
http://www.sjbaker.org/steve/lego/motor_speed.html
If it does then presumably the question is whether the command you are using will cease when either of the rotation counters reaches the specified limit. If that is the case then both motors will stop, even if one is lagging. Could be that you would have to issue separate commands for each motor.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
Re: Motor Issue and NXC
just an idea, but what if you try RotateMotorPID instead of RotateMotorEx ?
Re: Motor Issue and NXC
Came across an earlier thread in this section by the title of 'Can't drive straight forward' which might contain some info.
Don't know how to post an internal link so here is the full thing:-
https://sourceforge.net/apps/phpbb/mind ... 2577#p2577
Don't know how to post an internal link so here is the full thing:-
https://sourceforge.net/apps/phpbb/mind ... 2577#p2577
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
Re: Motor Issue and NXC
"A program in NXT-G seems to act the same way"
I have had this issue as well in NXT-g( i think). Since this is all i use. I can only say how i have worked around it in NXT-g. In my project X2 if i need say B/C motors to run in an opposit direction and keep a accurate count. I have been using two blocks instead of the one and use in loop "crow barred"(thanks Brian) or parallel at that point.
I have had this issue as well in NXT-g( i think). Since this is all i use. I can only say how i have worked around it in NXT-g. In my project X2 if i need say B/C motors to run in an opposit direction and keep a accurate count. I have been using two blocks instead of the one and use in loop "crow barred"(thanks Brian) or parallel at that point.
"Anyone who has never made a mistake has never tried anything new."
Albert Einstein
Albert Einstein
Re: Motor Issue and NXC
I spent a lot of time trying to figure out how the "sync" feature works with Lego motors and I came to the conclusion that it doesn't even do a very good job of keeping a robot running straight, much less allowing it to do precision turns, or even worse, precision pivots. So I wrote my own sync code which seemed to work fairly well.
Re: Motor Issue and NXC
This code is completely untested but it might work.
In theory this will work with either the standard NXT firmware or the enhanced NBC/NXC firmware.
John Hansen
Code: Select all
mutex MotorBMutex;
mutex MotorCMutex;
long degreesB, degreesC, holdTimeB, holdTimeC;
int powerB, powerC;
inline void HoldAtPosition(byte motor)
{
SetOutput(motor,
PowerField, 0,
OutputModeField, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED,
RegModeField, OUT_REGMODE_SPEED,
RunStateField, OUT_RUNSTATE_RUNNING,
// experiment with the PID values if you want
RegPValueField, PID_3, RegIValueField, PID_1, RegDValueField, PID_1,
UpdateFlagsField, UF_UPDATE_SPEED+UF_UPDATE_MODE+UF_UPDATE_PID_VALUES);
}
task rotateBThenHold()
{
Acquire(MotorBMutex);
RotateMotor(OUT_B, powerB, degreesB);
HoldAtPosition(OUT_B);
Wait(holdTimeB);
Release(MotorBMutex);
}
task rotateCThenHold()
{
Acquire(MotorCMutex);
RotateMotor(OUT_C, powerC, degreesC);
HoldAtPosition(OUT_C);
Wait(holdTimeC);
Release(MotorCMutex);
}
void MoveMotors(int pwrB = 75, int pwrC = 75, long degB = 400, long degC = 400, int holdB = SEC_1, int holdC = SEC_1)
{
// setup the global motor parameters
degreesB = degB;
degreesC = degC;
holdTimeB = holdB;
holdTimeC = holdC;
powerB = pwrB;
powerC = pwrC;
// start the two motor tasks
start rotateBThenHold;
start rotateCThenHold;
// wait a bit to give the threads a chance to get started
Wait(MS_1); // 1 ms is probably sufficient. adjust if needed.
// the code below will make this subroutine wait here until both
// rotate tasks are finished
Acquire(MotorBMutex);
Acquire(MotorCMutex);
Release(MotorCMutex);
Release(MotorBMutex);
}
void DrawBPosition()
{
ResetRotationCount(OUT_B);
int x = 0;
while (true) {
int y = MotorRotationCount(OUT_B) + 32;
PointOut(x, y);
Wait(MS_10);
x++;
if ((x % 100) == 0)
ClearScreen();
x %= 100;
}
}
task main()
{
MoveMotors(75, -75);
// the motors should stay "locked" in their position while DrawBPosition runs (forever)
// try turning the B motor by hand to see how the firmware responds to deviations from
// current position
DrawBPosition();
// Off(OUT_B);
// Off(OUT_C);
// while(true);
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 346
- Joined: 27 Sep 2010, 03:05
- Contact:
Re: Motor Issue and NXC
I think that's what I needed. Thanks, John.
Steve
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
Re: Motor Issue and NXC
hi,
actually I'm really curious why you need to use those tons of code just to make the motors reach their target correctly with PWM >50%.
What in the original RotateMorEx (~PID) code or firmware code is faulty?
Will there be a workaround so that RotateMorEx (~PID) will work correctly in the future?
actually I'm really curious why you need to use those tons of code just to make the motors reach their target correctly with PWM >50%.
What in the original RotateMorEx (~PID) code or firmware code is faulty?
Will there be a workaround so that RotateMorEx (~PID) will work correctly in the future?
Re: Motor Issue and NXC
The problem is not with RotateMotor per se but with the way the underlying firmware handles the turn percent parameter. It just does not do a very good job of synchronizing two motors turning in different directions. Possibly this could be fixed with a firmware modification but the output module code is a little tricky (at least for me, anyway).
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 1 guest