Can't control rov2 servo by using MAV_CMD_DO_SET_SERVO

I’m a Rookie in coding,and i have project which using QT create a UI to control my rov2.below is my code in qt creator.

mavlink_message_t msg;    
       uint8_t buf[MAVLINK_MAX_PACKET_LEN];

        //test servo
            mavlink_msg_command_long_pack(255,           // System ID
                                          1,        // Component ID
                                          &msg,           // MAVLink message
                                          0,                  // Target system ID
                                          0,                  // Target component ID
                                          MAV_CMD_DO_SET_SERVO, // Command ID
                                          0,                  // Confirmation
                                          1700, 0, 0, 0, 0,0);     // Parameters
                    qint64 len2 =mavlink_msg_to_send_buffer((uint8_t*)buf,&msg);
                     m_udpsend->writeDatagram((const char*)buf,QHostAddress(""),14550);

I can recieve rov message(like heartbeat) from udp connection,but when sending these codes,rov have no reflect.
by the way I qdebug “(const char*)buf” in outpout,it is “0x74ca19”,is normal and corret?
thank u.

Hi @Baltard, welcome to the forum :slight_smile:

A couple of things that might help:

  1. The vehicle generally has both system ID and target ID as 1, not 0.
  2. is the IP address of the topside computer - if that’s supposed to be the vehicle IP then it should (generally) be
1 Like

@EliotBR Thanks for the prompt response!I have tried your advice,the vehicle system ID and target
ID are both 1,and I changed the IP adress to,but it doesn’t seem to work :disappointed_relieved:.I read a pymavlink code,before I control the servo maybe I should change the MAV_MODE?Another question is should I send heartbeat message to the rov2 Regularly,is necessary for just test a servo?I feel a little confuse about the progress.Looking forward to your response.

I’ve just taken another look at this and it seems like you’re trying to set the PWM of servo 2, which is pretty much always assigned as a motor for use in controlling the vehicle (which generally need to be controlled with MANUAL_CONTROL or RC_CHANNELS_OVERRIDE messages, while the vehicle is armed).

If you want to use the DO_SET_SERVO command you’ll need to ensure the SERVOn_FUNCTION parameter (where n is the servo you’re trying to control) is set to Disabled (-1). This is not recommended for motion control outputs, so normally you would only do this for outputs 7+ in a standard BlueROV2, or 9+ if you’re using the heavy configuration.

If you’re using a Pixhawk note that servos 1-8 are MAIN 1-8, and servos 9-14 are AUX 1-6.

Thank you,Eliot!Today, I suecessfully control my rov. :clap:

1 Like