[NXC]Motor-control-functions

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
matzzn
Posts: 10
Joined: 29 Nov 2011, 17:51

[NXC]Motor-control-functions

Post by matzzn »

Hello

I am currently examining the commands RotateMotor() and RotateMotorPID().

I have come to the conclusion that the motor always overshoots the target position. I could not eliminate the problem by changing the PID values.

http://mindstormsforum.de/viewtopic.php ... 9f5cd891a0

I came across a program that controls the motors better than the firmware. (written in NXC for PC based programs)

http://mindstormsforum.de/download/file ... 9f5cd891a0

http://www.mindstorms.rwth-aachen.de/tr ... torControl

Is there a possibility, that we NXC programmers get such a function? I'm not really happy with the current functions :|

_________________________________________________________________________________________________________________________________

http://roboticsaumair.jimdo.com
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC]Motor-control-functions

Post by afanofosc »

There have been a number of discussions on this topic here in the past. Here's one thread where I posted an NXC function that could be used as an alternative to the stock RotateMotor function:

http://sourceforge.net/apps/phpbb/mindb ... =10#p12513

Of course, NXC users are strongly encouraged to create functions that do exactly what they need and then share them with others.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
matzzn
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]Motor-control-functions

Post by matzzn »

Here's one thread where I posted an NXC function that could be used as an alternative to the stock RotateMotor function:
I've seen this already. This is the result:

https://www.dropbox.com/s/f8hn8jwymiywx ... ontrol.jpg

I can not see any improvement...
Of course, NXC users are strongly encouraged to create functions that do exactly what they need and then share them with others.
So there will never be new motor functions.

_________________________________________________________________________________________________________________________________

http://roboticsaumair.jimdo.com
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: [NXC]Motor-control-functions

Post by HaWe »

I am really curious why every adjustment of any P, I, D -Values in RotateMotorPID doesn't have any effect on overshooting: this is always 40-50° in every single case... :roll:
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC]Motor-control-functions

Post by afanofosc »

matzzn wrote: I've seen this already. This is the result:

https://www.dropbox.com/s/f8hn8jwymiywx ... ontrol.jpg

I can not see any improvement...
I have no idea where you got that graph from. Perhaps you could post the full source code which you used to produce it? What does the graph look like using the stock RotateMotor API function? What do the graphs look like when you use RotateMotorExPID and pass in various different values for the parameters?

The code I pointed you toward is easily modifiable and you absolutely will get different curves depending on how you modify the code. Modify it until it does what you want.
So there will never be new motor functions.
There will be new motor functions when someone helps me write better ones. Are you willing to help?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
matzzn
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]Motor-control-functions

Post by matzzn »

I have no idea where you got that graph from. Perhaps you could post the full source code which you used to produce it?
I took your code, changed the rotation to 90° and monitored the rotation-count in Labview.
RotateMotorExPID
I don't know if there's a difference to RotateMotorPID but here are some graphs with different values:

P,I,D
20,40,80
20,40,100
20,40,120

http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984

20,60,80
20,60,100
20,60,120

http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984

40,40,80
40,40,100
40,40,120

http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984

40,60,80
40,60,100
40,60,120

http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984
http://mindstormsforum.de/download/file ... c6cad61984
Modify it until it does what you want.
What values should i change? (with reference to the graph)
There will be new motor functions when someone helps me write better ones. Are you willing to help?
I don't know much about low-level programming but here is a good motor control code:

http://www.mindstorms.rwth-aachen.de/tr ... torControl

download:
// + MotorControl.nxc
// |-+ Controller.nxc
// |-- MotorFunctions.nxc
// |-- SpeedFromPosLookup.nxc
// |-- ControllerCore.nxc
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC]Motor-control-functions

Post by afanofosc »

The links you posted all result in this message:
Du bist nicht berechtigt, diese Seite anzusehen, von ihr herunterzuladen oder auf sie zu linken.
PID values can only be multiples of 32. Use the PID_0 through PID_7 constants which are 0, 32, 64, 96, 128, 160, 192, and 224

http://bricxcc.sourceforge.net/nbc/nxcd ... tants.html

Any other values are truncated down to the next lower value that is a multiple of 32.

I am not a PID control expert so I do not know what values will work best. The function I posted is high level code which is pretty straight-forward. The modifications I think you could make are not so much to PID values but to such things as what percent of the required rotation is ramp up, what percent is full power, what percent is ramp down, how long is the motor braked when the destination is reached, etc... I would recommend trying rotations much much greater than 90 degrees since rotating a quarter turn at any speed faster than really slow doesn't give any control routine - either firmware or user-level code - to respond to rotation changes in time to avoid overshoot, etc...

What speed are you using when you tell the motor to turn 90 degrees? Have you tried a wide variety of speeds?

Have you tried the absolute position regulation API functions at all? They start with PosReg*.

I don't think there is any way I can use the code you link to for a general motor control routine.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: [NXC]Motor-control-functions

Post by HaWe »

Any other values are truncated down to the next lower value that is a multiple of 32.
why that??
is that a mathematical calculation problem?
matzzn
Posts: 10
Joined: 29 Nov 2011, 17:51

Re: [NXC]Motor-control-functions

Post by matzzn »

The links you posted all result in this message:
The pictures shows that different pid values result in a overshoot of the target position.
PID values can only be multiples of 32. Use the PID_0 through PID_7 constants which are 0, 32, 64, 96, 128, 160, 192, and 224
With such rough values ​​I need not even begin to find a good PID controller.
I would recommend trying rotations much much greater than 90 degrees since rotating a quarter turn at any speed faster than really slow doesn't give any control routine - either firmware or user-level code - to respond to rotation changes in time to avoid overshoot, etc...

What speed are you using when you tell the motor to turn 90 degrees? Have you tried a wide variety of speeds?
With a good motor controller you should get good results at any speed and angle. I know it's possible that the firmware reacts fast enough.
An intelligent regulation can decide when the rotation speed must be reduced to avoid overshooting.
Have you tried the absolute position regulation API functions at all? They start with PosReg*.
Yes, everything remains the same as with the normal motor functions.


I can already see this do not lead to a result. I should probably make my own motor functions.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC]Motor-control-functions

Post by afanofosc »

It seems very unlikely to me that the PosReg* absolute position regulation API functions produce "the same" results as the RotateMotor* API functions for "everything". They work completely differently from how the RotateMotor functions work so it seems impossible to me that they perform identically, which seems to be what you are suggesting.

If you have not tried all the PID constants values to see what impact they have on the firmware's internal motor control routine then you do not know that they cannot produce good results.

If you have not tried adjusting the ramp up and ramp down portions of the total motor movement in the routine I posted then you can't possibly say that you've tried everything to get that routine to work in a way that suits your needs.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests