Subject:
|
Re: Fun with MindStorms Rotational Sensors
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 3 Jun 1999 07:24:27 GMT
|
Original-From:
|
Ben Williamson <BENW@POBOX.COMihatespam>
|
Viewed:
|
1260 times
|
| |
| |
On Thu, 3 Jun 1999, Hari Wiguna wrote:
> First, I'd like to thank Hao-yang Wang for letting all of us know about the
> availability of rotational sensors.
Agreed, I went and bought one too. :)
I'd like to get really smooth speed and position control of a motor using
this thing for feedback. Motors with two speeds (go and stop) get boring
after a while, all the really cool robots I've seen glide smoothly to a
stop as they reach a target. Perhaps an elevator that doesn't cause
minifigs jarring bone injuries would be a good start. :)
I spent a while trying to build a PID controller, working from vague
memories of an undergrad control systems subject. Feel free to jump in
and correct me on this stuff, it's not my field and I hated the subject.
PID stands for Proportional, Integral, Derivative. The idea is to drive a
motor so that the shaft position (as measured by the rotation sensor)
tracks some input signal. The difference between the input signal and the
shaft position is the "error". The feedback that's applied to the motor
has components that are Proportional to the error, the time-Integral of
the error, and the time-Derivative of the error. The constants that
balance these components are P, I and D.
I've attached my NQC source below. The main task generates a sawtooth
input signal in the "target" variable, while the tracking task measures
the error and calculates the feedback to apply. Unfortunately the
tracking loop runs so slowly that it only updates the feedback about twice
a second! As a result, the shaft just overshoots and oscillates back
and forth around the target position. Has anyone tried something like
this under legOS rather than bytecode? I'll get around to it at some
stage, but just lately I seem to have become obsessed with poking around
in the Linux kernel. :)
Cheers,
- Ben.
-------------------------------------------------------------------
Ben Williamson benw@pobox.com http://www.pobox.com/~benw/
#define ANGLE IN_1
#define MOTOR OUT_A
#define P 10
#define I 5
#define D -10
#define SCALE -40
int target;
int previous;
int current;
int error;
int integral;
int differential;
int output;
task tracking
{
while (1 == 1) {
previous = current;
current = ANGLE;
error = current - target;
integral = (integral * 99 / 100) + error;
differential = current - previous;
output = ((P*error) + (I*integral) + (D*differential)) / SCALE;
if (output < -7) {
output = -7;
} else if (output > 7) {
output = 7;
}
if (output < 0) {
output = 0 - output;
Rev(MOTOR, output);
} else if (output > 0) {
Fwd(MOTOR, output);
} else {
if (error == 0) {
Off(MOTOR);
} else {
Float(MOTOR);
}
}
}
}
task main
{
Sensor(ANGLE, IN_ANGLE);
ClearSensor(ANGLE);
target = 0;
current = 0;
integral = 0;
differential = 0;
start tracking;
while (1 == 1) {
Sleep(500);
target = 50;
Sleep(500);
while (target > 0) {
target -= 1;
Sleep(10);
}
}
}
--
Did you check the web site first?: http://www.crynwr.com/lego-robotics
|
|
Message has 1 Reply: | | Re: Fun with MindStorms Rotational Sensors
|
| (...) It _is_ my field (I do control system research), but I won't go into great depth - I don't think this is the right forum! I've tried this too - and it sort of worked (using just proportional feedback I can control a shaft's position _fairly_ (...) (25 years ago, 3-Jun-99, to lugnet.robotics)
|
Message is in Reply To:
| | Fun with MindStorms Rotational Sensors
|
| First, I'd like to thank Hao-yang Wang for letting all of us know about the availability of rotational sensors. In case you missed it: >I saw both the rotation sensor (9756) and the temperature sensor (9755) at >www.legoworldshop.com last week. >( I (...) (25 years ago, 3-Jun-99, to lugnet.reviews, lugnet.robotics)
|
5 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|