Arduino Nano Every + SBUS + DJI Ronin S: How to reset position

Does anyone know how to send the re-center/return home command to Ronin S via Sbus? I got the pan tilt and roll working. I use Arduino Nano every + inverter to send the commands. Using sbus library If I want to turn left I send number < 1023 to CH1 and right > 1023 to CH1 etc. and that works fine but I have no idea how to send the recenter command. I have tried sending values 0-2048 to channels 5,6 and 7 and toggling the values back and forth (imitating the trigger douplecklick) but nothing happens.

#include <BMC_SBUS.h>     // ALERT!!!! CHANGE SERIAL PORT NUMBER IN BMC_SBUS.h FOR UNO.

//Params
boolean firstrun = true;
boolean needreset = true;     //false if reset just happened

//Declare BMC_SBUS Object
BMC_SBUS mySBUS;

// Sbus delay value
const int sbusWAIT = 70; // frame timing delay in msecs

// Declare sbus control channels
int panChannel = 1;
int tiltChannel = 2;
int rollChannel = 4;
int speedChannel = 5;
int modeChannel = 6;
int triggerChannel = 7;

//data from pc

const byte numChars = 32;     //maxlength of pcmessage
char pcmessage[numChars];     //message from pc serial
char oldmessage[numChars];    //previous message from pc serial
int Xsuunta = 1023;           //x-axis directioin
int Ysuunta = 1023;           //y-axis direction
int Mode = 1;                 //gimbal mode
int cnt = 0;                  //cycle counter
int msgi = 0;                 //number of messages received
boolean newData = false;      //True if new data is being read
int dataNumber = 0;


//Arduino start setup
void setup() {
  Serial.begin(9600);
  Serial.setTimeout(100);
  mySBUS.begin();
}

//Arduino main loop
void loop() {
  // Run gimbal positioning to zero on first loop.
    if (firstrun == true){
      Serial.print("STARTING GIMBAL. LCD OFF\n");
      Serial.print("go\n");
      zeroNow();
      firstrun = false;
    }
    
    readPC();	//commands in
    //Serial.print("go\n"); //Inform through serial that ready for next message
}

void(* resetFunc) (void) = 0;//declare reset function at address 0

//Read  serial string ex. "102310231\n" from pc.
void readPC(){
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;

    if(Serial.available() > 0) {
      rc = Serial.read();
      needreset = true;
      cnt = 0;

      if (rc != endMarker) {
        pcmessage[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
            ndx = numChars - 1;
        }
      }
      else {
          pcmessage[ndx] = '\0'; //terminate the string
          ndx = 0;
          msgi++;
          newData = true;
          makenumbers();
          Serial.print("go\n");   
      }
    }
}

//Make integers out of received serial message. Bits:(1-4 X-axis, 5-8 Y-axis, 9 Mode)
void makenumbers() {
    if (newData == true) {
        if (pcmessage[0] == 'q'){			//if q is received
          mySBUS.Servo(panChannel,1023);
          mySBUS.Servo(tiltChannel,1023);
          mySBUS.Update();
          mySBUS.Send();
          resetFunc(); //call reset 
        }
        else if (pcmessage[0] == 'z'){
          zeroNow();						//if z is received
        }
        else{
        char xin[4];
        char yin[4];
        char modein[1];
        xin[0] = pcmessage[0];
        xin[1] = pcmessage[1];
        xin[2] = pcmessage[2];
        xin[3] = pcmessage[3];
        yin[0] = pcmessage[4];
        yin[1] = pcmessage[5];
        yin[2] = pcmessage[6];
        yin[3] = pcmessage[7];
        modein[0] = pcmessage[8];
        
        Xsuunta = atoi(xin); //combine xin characters to int
        Ysuunta = atoi(yin); //combine yin characters to int
        Mode = atoi(modein); //combine modein chars to int
        }
        
        if (Xsuunta < 1 || Xsuunta > 2047) Xsuunta = 1023;
        if (Ysuunta < 1 || Ysuunta > 2047) Ysuunta = 1023;
        
        newData = false;

        sendsbus(); //Send to gimbal
    }
    
}
void sendsbus(){
  // Read data. Gimbal limits 0-2047. Middle = 1023
    int sendValueX = Xsuunta;
    int sendValueY = Ysuunta;
    int sendMode = Mode;

    // Set sbus pan and tilt
    mySBUS.Servo(panChannel,sendValueX);
    mySBUS.Servo(tiltChannel,sendValueY);
    //mySBUS.Servo(speedChannel,0);
    //mySBUS.Servo(modeChannel,sendMode);
    //mySBUS.Servo(triggerChannel,0);

    // Update SBUS object and send data
    mySBUS.Update();
    mySBUS.Send();
    // Delay for SBUS
    delay(sbusWAIT);
}

//TRYING TO GET THE GIMBAL TO RECENTER
void zeroNow(){
      mySBUS.Servo(5,1);
      mySBUS.Servo(6,1);
      mySBUS.Servo(7,1);
      mySBUS.Update();
      mySBUS.Send();
      delay(100);
      mySBUS.Servo(5,2048);
      mySBUS.Servo(6,2048);
      mySBUS.Servo(7,2048);
      mySBUS.Update();
      mySBUS.Send();
      delay(100);
      mySBUS.Servo(5,1);
      mySBUS.Servo(6,1);
      mySBUS.Servo(7,1);
      mySBUS.Update();
      mySBUS.Send();
      delay(100);
      mySBUS.Servo(5,2048);
      mySBUS.Servo(6,2048);
      mySBUS.Servo(7,2048);
      mySBUS.Update();
      mySBUS.Send();
      delay(100);
      mySBUS.Servo(5,1);
      mySBUS.Servo(6,1);
      mySBUS.Servo(7,1);
      mySBUS.Update();
      mySBUS.Send();
      cnt = 0;
      msgi = 0;
      needreset = false;
      Xsuunta = 1023;
      Ysuunta = 1023;
      Serial.print("Recenter ok?\n");
}

If I want to turn left I send number < 1023 to CH1 and right > 1023 to CH1 etc. and that works fine

If less than 1023 means turn left and greater than 1023 means turn right then what does 1023 mean ?

UKHeliBob:
If less than 1023 means turn left and greater than 1023 means turn right then what does 1023 mean ?

It's the middle position. 1022 is the slowest to the left, 0 is the fastest to the left. 1024 is the slowest to the right 2048 is the fastest to the right. if you send f.ex. 2000 to channel 1 gimbal will turn right until you send 1023.

I would still like to know how to recenter the gimbal with s-bus commands. I suppose I could use an actuator to physically "Double click" the trigger (recenter) on the gimbal but that seems worse solution than actually sending the command. :confused:

I would still like to know how to recenter the gimbal with s-bus commands

Do you mean that you want the current position to become the centre ?

UKHeliBob:
Do you mean that you want the current position to become the centre ?

No. I just want the gimbal to return to home postiion to the center. DJI Ronin recenters itself to the middle when the physical trigger is pushed twice. The trigger button channel should be channel 7 but it does not work.

    // Set sbus pan and tilt
    mySBUS.Servo(panChannel,sendValueX);
    mySBUS.Servo(tiltChannel,sendValueY);

You say that this works, so why do you not use the channel names in zeroNow() ?

What is the first parameter in

mySBUS.Servo()

because in zeroNow() you use 5, 6 and 7 not the channel names. I thought that it was the servos that you wanted to move to the centre

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.