Vehicle doesn't preserve its height in offboard mode

hello all,
i am using pixhawk 6c mini (uploaded autopilot version px4 v1.15) and raspberry pi as companian computer. i dont use gps. i use optical flow and tf-03 which is published in raspberry pi with ros2.

when i give a trajectory x and y drones height is reduced while it goes to the point. even it sometimes touches the ground. so for instance i will share a graphic. this graphic contains distance sensor [current distance], vehicle odometry [position z], trajectory setpoint [position z].

i was suspecting if trajectory setpoint z is reduced but it is always in the same value. so i started to suspect about barometer. i wonder if barometer affect this problem.

here is the flight log: https://review.px4.io/plot_app?log=7207702f-978c-4716-a085-ba166e31d8ac
how to solve this problem?

Did you account for gravity in your offboard?

9.2 something force…

i guess no. how can i do that?

How is your offboard setup works ? What code?

well, i just set a TrajectorySetpoint object inside a function.

void publishTrajectorySetpoint()
{
    trajectorySetpointMsg msg{};
    msg.position[0] = setpoint.position.x;
    msg.position[1] = setpoint.position.y;
    msg.position[2] = -setpoint.position.z;
    msg.velocity[0] = setpoint.velocity.x;
    msg.velocity[1] = setpoint.velocity.y;
    msg.velocity[2] = setpoint.velocity.z;
    msg.yaw = setpoint.attitude.yaw; // [-PI:PI]
    msg.timestamp = this->get_clock()->now().nanoseconds() / 1000;
    pub.trajectory_setpoint->publish(msg);
}

// this enables offboard control
void publishOffboardControlMode()
{
    offboardControlModeMsg msg{};
    msg.position = true;
    msg.velocity = false;
    msg.acceleration = false;
    msg.attitude = false;
    msg.body_rate = false;
    msg.direct_actuator = false;
    msg.timestamp = this->get_clock()->now().nanoseconds() / 1000;
    pub.offboard_control_mode->publish(msg);
}

@Patrik_Pordi1 is working on this right now with @bresch

1 Like