OFFBOARD mode problem

Attach RC and fly your drone manually.
I did not fly without RC, because in autinomous flight so many reasons your drone can crash - you have to have manyal failsafe control if something goes wrong, anyway.
In your log - “takeoff detected”, so the problem is not in autonomous flight program, it’s in the drone itself, test manual flight.

@copterspace I got the RC and I am going to test the drone with RC.
I will update you about the test result.

@copterspace
I tested my drone with your python script (fly_jmavsim.py)
For the safety purpose, I removed drone’s propellers and observed the speed of the motors. The drone tried to takeoff due to the RPM increasing,
this is the logs result:
https://review.px4.io/plot_app?log=613014ef-e000-4be8-8477-9791882de093

I have two questions:
I subscribed to /mavros/state topic, the mode didn’t change to OFFBOARD mode. After executed the code, the drone mode changed to: “AUTO.TAKEOFF

  1. May I know even in the code you change the mode to OFFBOARD mode, why it didn’t change ?
  2. From the logs, it seems the drone takeoff and move to altitude :2.5m, can I reduce this number to 1m ?
  1. Mode changed to OFFBOARD, see the diagram in your flight review (on mouse pointer it shows flight mode):

  2. Change MIS_TAKEOFF_ALT param

Hi @copterspace
Thank you for your help, I could change the altitude to 1m in the QGroundcontrol software. I tested again and the link below is the test result’s video.

https://drive.google.com/drive/folders/179jPpZLetP8EUxpVsfcYJJQriP0tWyvM?usp=sharing

Test conclusions from the observation RPM:

  1. Drone could take-off
  2. I could change the speed of motors with ‘u’ and ‘d’, land the drone with ‘q’ keyboard.
    Problem:
    When I run the code second times, the drone didn’t run the code properly. I could turn on the motors but I couldn’t change the motor speed with keyboard.

BTW, I run the program a few times, I got the same result.
Could you please advise me what would be the root of issue ?

Beside that, I connected GND,Tx,Rx form Raspberry Pi to Pixhawk, however I noticed in your websit that you connected +5V as well. May I know the reseaon ? Couldn’t be my issue reason ?

I ran it several times, it worked OK.
You should make experiments with flying drone (which is stable in POSITION mode), I think, beacause with props detached drone pose estimator does not understand if it flies or not - it is not offboard code issue, it’s issue of detached props.
+5v is not the reason, +5v you may connect, for example, if your pixhawk is not connected to drone and you with to power it from PI.

@copterspace Thank you so much for your advise,
I am going to test the drone and will update you.

@copterspace
First of all, I want to thank you for your help and valuable advises. I could successfully control my drone with your python script.

Test Results:
The drone could take-off after run the python script (fly_jmavsim.py ) and I could control the drone with my laptop’s keyboard

‘q’ set_mode(0,“AUTO.LAND”)
‘u’ setvel.linear.z
‘d’ setvel.linear.z
curses.KEY_LEFT: setvel.angular.z
curses KEY_RIGHT setvel.angular.z
curses KEY_UP setvel_forward
curses.KEY_DOWN setvel_forward
‘s’ setvel_forward=setvel.linear.z=setvel.angular.z =0

During the test, I had two issues which I need your advice:

  1. To take of the drone, I had to press ‘u’ a few times, then the drone could take-off otherwise, it only turned on the motors and stay on the ground.

  2. When I change the linear velocity with pressing ‘u’ and the when I wanted to stop the drone at a specific height with pressing ‘s’, it supposed to stop at that altitude, however it drift down by itself. It can be seen in the video, the drone drift down even it hit the ground and one of the landing gear was broken.

I’ve uploaded the test result video in the below link for your review and advise.
Thanks in advance.

https://drive.google.com/drive/folders/179jPpZLetP8EUxpVsfcYJJQriP0tWyvM

Your issues caused by overall flight performance, not by offboard code.
To improve vertical control - you may use distance sensor, TFMINI, for example.
To improve horizontal control - you may try optical flow, and/or GNSS system.
Also flight control depends on IMU quality, frame vibration level, and PIDs of your setup.
You should test and improve you setup with sticks in Position mode, once you suceed - offboard code will also work better.

@copterspace
I have plan to test the drone indoor environment ( non-GPS), I am going to use Realsense camera (T265).
Can I improve vertical/horizontal control by this camera?

You used “Velocity setpoint” in your code. May I know if I use “Position setpoint” the result would be better ( drone drift down) ?

What you mean by “improve you setup with sticks in Position mode” ?

@copterspace
I want to say thank you so much for your help since I could manage to fly my drone and make it stable with your help.

I have an issue, I am using position setpoints control to navigate the drone in the x,y,z axis.
With this topic
“/mavros/setpoint_position/local"

And this function:

def linear_move(x,y,z):
pose.pose.position.x = x
pose.pose.position.y = y
pose.pose.position.z = z

It works fine.

When I want to change yaw , drone trying to change the yaw but it becomes out of the control and I have to change I’m the model to land manually.
For example to yaw 90 degree I am use the code below:

yawVal = 90
quat = quaternion_from_euler(0.0, 0.0,numpy.deg2rad(yawVal))

pose.pose.orientation.x = quat[0]
pose.pose.orientation.y = quat[1]
pose.pose.orientation.z = quat[2]
pose.pose.orientation.w = quat[3]
print(quat)

Could you please advise me that is the yaw control issue in my code ?

Thanks in advance

if you want to change yaw - you should not specify pose, because pose also contains pitch and roll.
you’d rather specify target yaw rate to rotate your drone

setvel.angular.z

untill you reach target yaw, then set yaw rate to 0.
here is example Вход в Aeronet, эпизод 4: Отыскать и бабахнуть / Хабр

@copterspace
I went through the link that you shared with me.
As far as I understand, you use velocity setpoint and you published to this topic:
"/mavros/setpoint_velocity/cmd_vel_unstamped"

I am using position setpoints control to navigate the drone in the x,y,z axis.
With this topic
“/mavros/setpoint_position/local"

Can I publish the data to the two topics at same time:

  1. “/mavros/setpoint_position/local" ---->To control the drone into x,y,z axis
  2. "/mavros/setpoint_velocity/cmd_vel_unstamped" ---->To control the drone’s yaw

Yes, you should try, I think, it may work. I did not test this.

May I know why you use velocity setpoint instead of position setpoint to control your drone?