Robotics StackExchange | Archived questions

Offboard PX4 with T265 and ROS / Does not Take off

Hello Everyone. Dear Community I know this is not the place to ask but somehow it is related to ROS because I am using MAVROS. So I will appreciate any suggestion. I want to share with you guys what I am doing now and what are the issues I am facing. First of all, this is my setup:

I have followed these instructions from the PX4 developer guide to use the offboard mode with a companion computer running ROS.

These are the instructions:

cd ~/catkin_ws/src
git clone https://github.com/Auterion/VIO.git
//build the package
cd ~/catkin_ws/src
catkin build px4_realsense_bridge
//Configure the camera orientation
<node pkg="tf" type="static_transform_publisher" name="tf_baseLink_cameraPose"
    args="0 0 0 0 0 0 base_link camera_pose_frame 1000"/>
//PX4 Tuning in QGroundControl
EKF2_AID_MASK   344    Set vision position fusion, vision velocity fusion, vision yaw fusion and external vision rotation accoring to your desired fusion model.
EKF2_HGT_MODE   Vision Set to Vision to use the vision a primary source for altitude estimation.
EKF2_EV_DELAY   175    Set to the difference between the timestamp of the measurement and the "actual" capture time. For more information see below.
EKF2_EV_POS_X   0.0    Set the position of the vision sensor with respect to the vehicles body frame.
EKF2_EV_POS_Y   0.0    Set the position of the vision sensor with respect to the vehicles body frame.
EKF2_EV_POS_Z   0    Set the position of the vision sensor with respect to the vehicles body frame.

//Running VIO bridge
cd ~/catkin_ws/src
roslaunch px4_realsense_bridge bridge.launch
//running mavros
roslaunch mavros px4.launch fcu_url:="/dev/ttyTHS2:921600" gcs_url:="udp://:14401@127.0.0.1:14550"

Until here everything works well. Then, I read the mavlink inspector and I got the odometry messages including the quaternion and XYZ position. When I move the drone I can see those values changing. So that means everything is ok until here.

The problem comes when I run the script to control the drone. The drone only is arming and is not taking-off. But when I run this code using the gazebo simulator it works fine and the iris drone fly. IN the real world is not working. Here is my code:

#!/usr/bin/env python
'''
This code is to control the position of the drone in the Z axis
Author: @Diego Herrera
email: alberto18_90@outlook.com
'''

import rospy
import mavros
from geometry_msgs.msg import PoseStamped
from mavros_msgs.msg import State
from mavros_msgs.srv import CommandBool, SetMode
from geometry_msgs.msg import Point

# Callback method for state subscriber
current_state = State()  # Reading the current state from mavros msgs


def state_callback(state):
    global current_state
    current_state = state


mavros.set_namespace()
local_position_publisher = rospy.Publisher(mavros.get_topic('setpoint_position', 'local'), PoseStamped,
                                           queue_size=10)  #
state_subscriber = rospy.Subscriber(mavros.get_topic('state'), State, state_callback)

arming_client = rospy.ServiceProxy(mavros.get_topic('cmd', 'arming'), CommandBool)
set_mode_client = rospy.ServiceProxy(mavros.get_topic('set_mode'), SetMode)

pose = PoseStamped()


def coordinates_xyz(data):
    print("Callback function")

    X = data.x
    Y = data.y
    Z = data.z
    print("X value: ", X)
    print("Y value: ", Y)
    print("Z value: ", Z)
    print("")
    # pose = PoseStamped()
    pose.pose.position.x = X
    pose.pose.position.y = Y
    pose.pose.position.z = Z
    # pose.header.stamp = rospy.Time.now()
    # local_position_publisher.publish(pose)


def position_control():
    print("Position control def")
    rospy.init_node('Offboard_node', anonymous=True)
    prev_state = current_state
    rate = rospy.Rate(20.0)

    # Sending a few points before start
    for i in range(100):
        local_position_publisher.publish(pose)
        rate.sleep()

    # We need to wait for FCU connection
    while not current_state.connected:
        rate.sleep()

    last_request = rospy.get_rostime()

    while not rospy.is_shutdown():
        now = rospy.get_rostime()
        if current_state.mode != "OFFBOARD" and (now - last_request > rospy.Duration(5.)):
            set_mode_client(base_mode=0, custom_mode="OFFBOARD")
            last_request = now

        else:
            if not current_state.armed and (now - last_request > rospy.Duration(5.)):
                arming_client(True)
                last_request = now

        if current_state.armed:
            print("Drone ready to fly")
        if prev_state.armed != current_state.armed:
            rospy.loginfo("Vehicle armed: %r" % current_state.armed)
        if prev_state.mode != current_state.mode:
            rospy.loginfo("Current mode: %s" % current_state.mode)

        prev_state = current_state
        rospy.Subscriber("SOKA_DRONE", Point, coordinates_xyz)
        pose.header.stamp = rospy.Time.now()
        local_position_publisher.publish(pose)
        rate.sleep()


if __name__ == '__main__':
    try:
        position_control()
    except rospy.ROSInterruptException:
        pass

As I said, this code works fine in gazebo-simulator but running in the real-world is only arming and not takeoff. I really need help with this. Any suggestions I will appreciate.

Asked by subarashi on 2021-02-01 08:47:09 UTC

Comments

Did you try arming and taking off using QGroundControl ? I think you need to use an TAKEOFF service and then publish a setpoint.

Asked by Sankeerth on 2021-02-01 10:03:29 UTC

Hi. I didn't try it, but I have another code that is calling takeoff service with 1 meter of altitude. I cannot call takeoff from Qgroundcontrol because I am afraid the altitude it will arrive, due to I am flying indoors it can crash the top of my lab.

Asked by subarashi on 2021-02-01 10:39:24 UTC

You can configure QGroundControl Takeoff altitude. When you issue ReturnToHome from QGC the drone moves to a height of 25 meters and lands. Is the code with takeoff service working?. Get TX2 started first and then connect the Flight controller to it(otherwise it may cause some serial communication problems.).

Asked by Sankeerth on 2021-02-01 10:55:13 UTC

The code with Takeoff service doesn't work. The communication with the TX2 works fine because I can see the odometry data in QGroundControl that comes from the Realsense T265 through Tx2...

Asked by subarashi on 2021-02-02 01:11:29 UTC

I think it would be better to post a query on the px4 forum and analyze the flight logs. They can be of more help.

Asked by Sankeerth on 2021-02-02 08:41:24 UTC

@subarashi Did you ever have an issue where the VIO node would always tell the Pixhawk it was facing due east?

Asked by nabatta on 2021-03-16 17:32:01 UTC

@nabatta Sorry for replying late... Yes, indeed the VIO always tells pixhawk through quaternion that it is facing due east. Have you fixed it?

Asked by subarashi on 2021-03-26 03:17:36 UTC

@subarashi No, I never found a good solution. I just start the node with the drone always pointing east so it all lines up

Asked by nabatta on 2021-04-04 14:31:20 UTC

Answers