APR motor control

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

APR motor control

Post by mattallen37 »

I have been extremely happy with the new NXC APR motor control; so much so, that I would like additional support.

What I want, is the ability to enter my own encoder value, and get a motor speed from the function. Here is an example of what I want:

Code: Select all

int speed;
long position;

void PosRegSetAngleEx(long input_val, long pos, int &spd){
  /*Call to the FW...*/
}

task main()
{
  SetSensorType(S1, IN_TYPE_ANGLE);
  SetSensorMode(S1, IN_MODE_ANGLESTEP);
  while (true)
  {
    PosRegSetAngleEx(SENSOR_1, position, speed);
    OnFwd(OUT_A, speed);
  }
}
I want to enter the current position (perhaps gotten from a sensor, or some other means), and the desired position. I want to have the calculated speed returned (which I could input directly into a motor command).

I know that the downside to it, would be that the speed would only get adjusted/updated once per loop (instead of constantly by the FW).

Another option, would be that when setting up APR in the program, you specify the input and the output. For input, you could specify something like "SENSOR_1" or "MotorTachoCount (OUT_B)". For the output, you could specify something like "OUT_C" or (what I really want), tell it to run a function (or piece of asm).

I have two main things I want to be able to do here.
1: Control an RCX motor, using an RCX rotation sensor as the encoder.
2: Control NXT motors through an I2C interface, and use the encoder values from one of them as the encoder (feed the encoder values into the motor port like normal).

I guess maybe I just need to learn to make my own PID control loop ... :sigh: Any advice on where to find an, easy to understand, guide?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: APR motor control

Post by aswin0 »

This is an easy introduction to PID. Itbiswritten for NXT-G, so it uses integer math. With floating point math it would have been even more simple.
My blog: nxttime.wordpress.com
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: APR motor control

Post by mattallen37 »

Thank you very much. I have read about half way through it already ;)
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: APR motor control

Post by aswin0 »

There was also a bunch of articles about PID controllers in Hispabrick magazine.

Btw, writing a PID controller is the easy part. The hard part is to tune a PID controller. I have still to master this. Once I wrote a program that tunes a PID by means of evolution, see my blog for a wrap up on this.
My blog: nxttime.wordpress.com
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: APR motor control

Post by schodet »

mattallen37 wrote:I have two main things I want to be able to do here.
1: Control an RCX motor, using an RCX rotation sensor as the encoder.
2: Control NXT motors through an I2C interface, and use the encoder values from one of them as the encoder (feed the encoder values into the motor port like normal)
I am afraid this is too specific to be useful in the firmware. Moreover, firmware code is not exactly... flexible.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests