APR motor control
Posted: 17 May 2011, 20:01
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: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?
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 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?