The Association of Model Submariners.

Would you like to react to this message? Create an account in a few clicks or log in to continue.

* THE FORUM FOR ALL THOSE INTERESTED IN BUILDING AND OPERATING MODEL SUBMARINES *



Join the AMS - Registered Forum users can become members of the AMS and it's free ...... To join send an email with your name , address and phone number to amstreasure@googlemail.com


For a guide to past events see the "Shows and Events" section.

Papplewick Pumping Station, Nottingham, April 9th & 10th


,

"***"

Who is online?

In total there are 4 users online :: 0 Registered, 0 Hidden and 4 Guests :: 1 Bot

None


Most users ever online was 180 on Tue Nov 05, 2019 6:03 am

Latest topics

» 27Mhz - Radio Ideas
Cheap Arduino Auto leveler  EmptyWed Jun 07, 2023 1:59 pm by david f

» Servo Depth controller
Cheap Arduino Auto leveler  EmptyMon Jun 05, 2023 1:03 am by geofrancis

» WW2 mini sub build
Cheap Arduino Auto leveler  EmptySun Jun 04, 2023 4:56 pm by SimonH

» Waterproof servos
Cheap Arduino Auto leveler  EmptySat Jun 03, 2023 10:02 am by geofrancis

» Robbe Seawolf V2
Cheap Arduino Auto leveler  EmptySun May 28, 2023 1:25 pm by geofrancis

» BEC - Switch mode
Cheap Arduino Auto leveler  EmptyMon May 22, 2023 11:28 am by geofrancis

» Cheap Arduino Auto leveler
Cheap Arduino Auto leveler  EmptySat May 13, 2023 11:23 am by C-3PO

» Pump for bladder system
Cheap Arduino Auto leveler  EmptyWed May 10, 2023 10:34 pm by tsenecal

» Wireless charging
Cheap Arduino Auto leveler  EmptyWed May 10, 2023 9:14 pm by geofrancis

Statistics

Our users have posted a total of 12002 messages in 1955 subjects

We have 977 registered users

The newest registered user is awilki47

2 posters

    Cheap Arduino Auto leveler

    avatar
    geofrancis


    Posts : 127
    Join date : 2021-09-24

    Cheap Arduino Auto leveler  Empty Cheap Arduino Auto leveler

    Post  geofrancis Thu May 11, 2023 2:38 pm

    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);
    }

    david f and C-3PO like this post

    C-3PO
    C-3PO


    Posts : 92
    Join date : 2018-11-21
    Location : Northamptonshire UK

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  C-3PO Sat May 13, 2023 11:23 am

    I have not tried code - but to get it to compile you need to add  < & > as per yellow highlights

    Cheap Arduino Auto leveler  Levell10

    Why do people hammer their code in the loop millions of times per second!!!

    Regards
    Jonathan

    david f and geofrancis like this post


      Current date/time is Sat Jun 10, 2023 8:36 am