Kalman filtered sensors to move servo
Tygerbot
Posts: 8
Hello everyone,
Im interested in learning how the Kalman Filter fuses two sensor together to get one result used in Hannos tilt object from the dance bot. Duane Degn redid Hannos tilt object for crazy robot girl by replacing the memsic accelerometer. I have had luck getting the memsic to work with the gyro. And now I want to be able to use Hannos tilt object to take the readings from the gyro, and the memsic fused by the Kalman Filter, and apply this to a servo. So in others words. As I tilt my sensors to the right (they are on the same breadboard). I want the servos horn to move to the right, and so on. How do you write a code from the tilt object to move the servo? Is this ramping? Can someone help, and get me started?
Thanks
Im interested in learning how the Kalman Filter fuses two sensor together to get one result used in Hannos tilt object from the dance bot. Duane Degn redid Hannos tilt object for crazy robot girl by replacing the memsic accelerometer. I have had luck getting the memsic to work with the gyro. And now I want to be able to use Hannos tilt object to take the readings from the gyro, and the memsic fused by the Kalman Filter, and apply this to a servo. So in others words. As I tilt my sensors to the right (they are on the same breadboard). I want the servos horn to move to the right, and so on. How do you write a code from the tilt object to move the servo? Is this ramping? Can someone help, and get me started?
Thanks
Comments
Welcome to the forums.
Could you tell us more about what your want the servo to do?
You might be making this harder than it needs to be. Your accelerometer and gyro are on a breadboard right? You want to move the breadboard and have your servo move some amount and direction based on this movement?
The sensors are not connected to the servo horn? If not, this is a very different problem (probably easier) than the DanceBot balancing problem.
What kind of Propeller board to you have?
Have you learned to control the servo on its own yet?
While the servo object in the Propeller Tool library has a demo program with it, I also wrote a small demo program it's in post #15 of my QuickStart servo tester thread.
Edit: Based on what I understand so far, I don't think you'll need the gyro or a Kalman filter. Just use a linear equation to relate the accelerometer reading to a pulse length to send to the servo.
1.Yes i want to be able to move the breadboard with the sensors on it, and have the servo match the movement.
2.The bread board is not connected to , or mounted to the servos horn.
3.Im using the prop usb stick
4. I have been practicing much with the servos. Moving them as well as ramping them.
5.I probally wont need the gyro or the Kalman filter to achieve this. But I would like to use Hanno's tilt object to accomplish this. i am very interested in fusing these two sensors with the Kalman filter to do this (learning purposes) so I can better understand the balance bot.
All I need is a little program to get started. Of course I dont want you to take all the fun out of it by doing the hole thing. I just want more or less a starter program. I have a propscope for the signals to help me, and viewport.
Hanno's tilt object doesn't apply to what you want to do. When you have a balancing bot, you'll want to use Hanno's object. It's not applicable to your current application.
You'll want a loop, probably repeating every 20ms, that reads the accelerometer and uses the reading to compute the desired servo position.
Start with two points. Have the accelerometer reading be "x" and the servo pulse length "y". What do you want "y" to be at one extreme of "x". What do you want "y" to be at the other extreme? You now should have two points to your linear equation. With two points you can compute the equation of the line. You might need to change the order things are multiplied to take into account the Propeller uses integer math.
I'm not sure off the top of my head. You want to come up with a relationship to accelerometer readings and pulse length. It's a nice algebra word problem.
A self leveling table is a different problem than the one your initially described (not much though). Since on a self leveling table the servo would influence the sensors. In your initial problem the servo didn't affect the sensors.
As long as the table is stationary (not flying through the air or driving over the ground) an accelerometer would be all that's need to keep it level.
This isn't a simple problem but it's not real hard either.
Again, you'll want a loop to read the sensor and the update the servo position. Since most servos are updated 50 times a second (20ms period) your loop doesn't need to be any faster than this (easy for the Prop).
There's example code to use an accelerometer and there's example code to control servos. It's unlikely there's code to do just what you want.
Chis the Carpenter of Rocket Brand Studios made a nice set of videos about making robots. I highly recommend them.
From the Rocket Brand Studio's home page click "I want to build a robot and I have no idea where to start." on the left side of the page. He explains the process pretty well.
The cornerstone of any servo is what's known as a PID structure. They come in many shapes and sizes but have a general similarity about them. They provide, primarily, target tracking but also integrating and/or derivating translations that are typically needed to match sensors to the actuator.
Filters, or just the raw measurements, will be directly feeding the inputs of the PIDs, with PID outputs commanding the actuators.
Duane's point about it being an algebra problem is spot on. Depending on the sensors you choose, you'll have to implement most of the following steps:
- Get a reading from your sensors
- Optionally run your filter
- Complementary or Kalman filter would go here
- Convert the results into an angular value
- If the result is from one of the filters, this may already be done
- If the result is just from accelerometer, you'll probably be using ATAN or ATAN2
- Map the range of the sensor reading to the range of your servo input
- Servos generally take an input value of 1000 for "far left", 1500 for "centered", or 2000 for "far right"
- Your sensor angle may be in degrees, radians, or some other form, like "-512 to +512". You'll need to convert from one to the other.
- Use the result of your math to set the servo value.
Jason
Jason