Hello, I'm a beginner with flowcode and I don't know how to program to control my HiTec HS-311 servomotor with the MPU6050...
You'll see what I tried in the attachment...
Can you send me a program that solves my problem?
Thank you!
Best regards,
Hugo D
Controlling a servomotor with the MPU6050 accelerometer
Controlling a servomotor with the MPU6050 accelerometer
- Attachments
-
- 1.JPG (85.29 KiB) Viewed 4125 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Controlling a servomotor with the MPU6050 accelerometer
Hello,
It looks like you are not initialising the MPU6050 component. Also the servo motor should be enabled after initialising the servo component.
Can you attach your project file so we can look at and edit that without having to start again.
It looks like you are not initialising the MPU6050 component. Also the servo motor should be enabled after initialising the servo component.
Can you attach your project file so we can look at and edit that without having to start again.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Controlling a servomotor with the MPU6050 accelerometer
Hello !
Thank you for your answer. I see what you mean about the initialization but to be honest I don't understand because I have to complete the Return Value and I don't know how to do it.
Attached is my complete program! Thank you in advance, you save me!
Thank you for your answer. I see what you mean about the initialization but to be honest I don't understand because I have to complete the Return Value and I don't know how to do it.
Attached is my complete program! Thank you in advance, you save me!
- Attachments
-
- Flowcode_test.fcfx
- (10.12 KiB) Downloaded 199 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Controlling a servomotor with the MPU6050 accelerometer
Hello,
Try this one instead, I have rearranged things slightly and added in a few more macro calls.
Try this one instead, I have rearranged things slightly and added in a few more macro calls.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Controlling a servomotor with the MPU6050 accelerometer
Wow, thank you!
That's work well! I'll get back to you if I have any more questions!
That's work well! I'll get back to you if I have any more questions!
Re: Controlling a servomotor with the MPU6050 accelerometer
SO I'll be right back because I have a new question:
The program you sent me works fine but the sensor is very sensitive and at the slightest movement the engine will rotate 180°. Would you know how to modify the program and make sure that when I turn my accelerometer 90° on the X axis, the servo turns 90°, when I turn my accelerometer 120°, the servo turns 120°, etc...
Thank you in advance!
The program you sent me works fine but the sensor is very sensitive and at the slightest movement the engine will rotate 180°. Would you know how to modify the program and make sure that when I turn my accelerometer 90° on the X axis, the servo turns 90°, when I turn my accelerometer 120°, the servo turns 120°, etc...
Thank you in advance!
- Attachments
-
- Flowcode_test.fcfx
- (10.12 KiB) Downloaded 200 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Controlling a servomotor with the MPU6050 accelerometer
Hello,
I think you probably first need to filter the values to reduce some of the sensitivity.
A simple way of doing this is to take say 10 readings, then add up all 10 readings into a long variable, divide the result by 10 and this should give you a nice averaged value to assign to the servo. Add more readings for better filtering.
To get the angle correct you will need to appropriatley scale the result before passing to the servo, different servo's turn different amounts so this may be a case of trial and error. You could also tweak the timings on the servo properties to reduce or increase the movement.
These blog posts may be of interest.
https://www.matrixtsl.com/blog/quadroco ... -and-gyro/
I think you probably first need to filter the values to reduce some of the sensitivity.
A simple way of doing this is to take say 10 readings, then add up all 10 readings into a long variable, divide the result by 10 and this should give you a nice averaged value to assign to the servo. Add more readings for better filtering.
To get the angle correct you will need to appropriatley scale the result before passing to the servo, different servo's turn different amounts so this may be a case of trial and error. You could also tweak the timings on the servo properties to reduce or increase the movement.
These blog posts may be of interest.
https://www.matrixtsl.com/blog/quadroco ... -and-gyro/
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel