How can I set mode to Offboard mode

asked 2022-03-27 10:36:41 -0500

sumeyra gravatar image

updated 2022-04-10 05:53:36 -0500

Hi guys,

I'm trying to control a drone in gazebo via mavros. I try to run a test node which set the mode to offboard, arm the drone and draw a square. When I run the node the drone takeoff and hold just a while then land. I cant set mode to offboard mode. Px4 and QGC show this warning 'WARN [mavlink] SET_POSITION_TARGET_LOCAL_NED coordinate frame 0 unsupported'. I couldn't find what the problem exactly is.
I use ros melodic, gazebo9,vmware ubuntu 18.04.

THIS IS MY OFFBOARD FUNCTION

def setOffboardMode(self):
        global sp_pub
        cnt = Controller()
        rate = rospy.Rate(20.0)
        k = 0
        while k < 10:
            sp_pub.publish(cnt.sp)
            rate.sleep()
            k = k + 1
        sp_pub = rospy.Publisher('mavros/setpoint_raw/local', PositionTarget, queue_size=1)
        rospy.wait_for_service('/mavros/set_mode')

        try:
            flightModeService = rospy.ServiceProxy('/mavros/set_mode', mavros_msgs.srv.SetMode)
            response = flightModeService(custom_mode='OFFBOARD')
            return response.mode_sent
        except rospy.ServiceException as e:
            print
            "service set_mode call failed: %s. Offboard Mode could not be set." % e
            return False

THIRD TERMINAL IS THAT

sumeyra@ubuntu:~/PX4-Autopilot$ rosrun tulpar kare.py 
Waiting for arming...
Waiting for arming...
Waiting for arming...
Waiting for arming...
Waiting for arming...
Waiting for arming...
Waiting for arming...
Waiting for arming...
MAIN: SET OFFBOARD

(It just print 'set offboard' because of that I wrote this message on my code) But while running my code I did 'rostopic echo /mavros/state' which results in

sumeyra@ubuntu:~/PX4-Autopilot$ rostopic echo /mavros/state
header: 
  seq: 44
  stamp: 
    secs: 1648394216
    nsecs: 419879279
  frame_id: ''
connected: True
armed: False
guided: True
manual_input: False
mode: "AUTO.LOITER"
system_status: 3
---
header: 
  seq: 54
  stamp: 
    secs: 1648394230
    nsecs: 332277808
  frame_id: ''
connected: True
armed: True
guided: True
manual_input: False
mode: "AUTO.TAKEOFF"
system_status: 4
---
header: 
  seq: 62
  stamp: 
    secs: 1648394246
    nsecs: 270976013
  frame_id: ''
connected: True
armed: True
guided: True
manual_input: False
mode: "AUTO.LOITER"
system_status: 4
---
header: 
  seq: 79
  stamp: 
    secs: 1648394276
    nsecs: 674984034
  frame_id: ''
connected: True
armed: True
guided: True
manual_input: False
mode: "AUTO.RTL"
system_status: 4
---

Could you help me to solve this problem guys?

FIRST TERMINAL IS THAT

sumeyra@ubuntu:~$ roslaunch mavros px4.launch fcu_url:="udp://:14540@192.168.1.36:14557"
... logging to /home/sumeyra/.ros/log/c22b2070-ade0-11ec-b15a-000c2971bdc0/roslaunch-ubuntu-25341.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/sumeyra/.ros/log] is over 1GB.
It's recommended that you use the 'rosclean' command.

started roslaunch server http://127.0.0.1:39321/

SUMMARY
========

CLEAR PARAMETERS
 * /mavros/

PARAMETERS
 * /mavros/camera/frame_id: base_link
 * /mavros/cmd/use_comp_id_system_control: False
 * /mavros/conn/heartbeat_rate: 1.0
 * /mavros/conn/system_time_rate: 1.0
 * /mavros/conn/timeout: 10.0
 * /mavros/conn/timesync_rate: 10.0
 * /mavros/distance_sensor/hrlv_ez4_pub/field_of_view: 0.0
 * /mavros/distance_sensor/hrlv_ez4_pub/frame_id: hrlv_ez4_sonar
 * /mavros/distance_sensor/hrlv_ez4_pub/id: 0
 * /mavros/distance_sensor/hrlv_ez4_pub/orientation: PITCH_270
 * /mavros/distance_sensor/hrlv_ez4_pub/send_tf: True
 * /mavros/distance_sensor/hrlv_ez4_pub/sensor_position/x: 0.0
 * /mavros/distance_sensor/hrlv_ez4_pub/sensor_position/y: 0.0
 * /mavros/distance_sensor/hrlv_ez4_pub/sensor_position/z: -0.1
 * /mavros/distance_sensor/laser_1_sub/id: 3
 * /mavros/distance_sensor/laser_1_sub/orientation ...
(more)
edit retag flag offensive close merge delete