I just found this video on youtube showing a very cheap arduino based sub leveler based on Atmega328 and a MPU6050 IMU looks interesting, I havent tested it myself.
- Code:
#include Wire.h
#include MPU6050_light.h
#include Servo.h
#include ServoInput.h
//Define Variables we'll be connecting to
double Setpoint, Input, Output, Gain1, Gain2;
ServoInputPin-3- TR; //angled brackets here
//Signal diveplane from receiver to PWM pin 2
ServoInputPin-2- Switch(800, 1800); //angled brackets here
//switch signal from receiver PWM pin 3 cal for 3Pos switch Transmitter channel 5 (mc-10)
const int NumPositions = 3;
Servo servoTR;
//creates a Servo with the name „servoTR“ =Tiefenruder
MPU6050 mpu(Wire);
void setup()
{
Serial.begin(9600);
Serial.flush();
Wire.begin();
mpu.begin();
//Serial.println(F("Calculating gyro offset, do not move MPU6050"));
//delay(1000);
mpu.calcGyroOffsets();
Serial.println("Done.");
//Input = mpu.getAngleX();
Setpoint = 100; //0-Referenz of gyro, approx. in degrees servo arm (0...180)
Gain1 = 5;
Gain2 = 7;
servoTR.attach(8); // Servo signal wire (yellow) connected to pin 8
}
void loop()
{
mpu.update();
float rudder = TR.getAngle();
// get angle of servo (0 - 180) TR input from receiver
int position = Switch.map(1, NumPositions); // get Switch pos 1-3
if (position ==1)
{
servoTR.write(Setpoint - mpu.getAngleX() * Gain1);
}
else if (position==2)
{
servoTR.write(Setpoint - mpu.getAngleX() * Gain2);
}
else
{
Output = rudder; // schleift Senderinput durch zu TR Servo
servoTR.write(Output);
}
// Serial.print("Switch Position: ");
// Serial.println(position);
//
// Serial.println(rudder);
//
// Serial.println("\tY: " + String(mpu.getAngleY()));
// delay(50);
}
» ExpressLRS - 868/915 Mhz equipment
» Flight controllers as sub levelers
» Bournville 2023
» Raspberry Pi Pico + ePaper display hat
» Help with 1:48 scale WW2 German U boat
» Problem with Futaba FX-30 and 40 MHz module
» Resurgam, Nordenfelts II & IV - George Garrett's works.
» Letter to BMFA to request the sharing of the 35MHz frequency for model subs in the UK.