Control autopilot and attitude with companion computer

Hello everyone
I want to control autopilot and attitude of copter with companion computer like Jetson Nano. I want to calculate distance to object with companion computer and send location of object to autopilot and then move to the object position. Can I possible to do this? Location data must be lat, long? Or can I use the X, Y, Z orientation or Roll, Pitch, Yaw to define the distance and then move?
Where I should begin this application? Can anyone help me?

Regards

Hello @joe_white, to achieve that you should send mavlink movement commands in guided mode. You can send commands to control the vehicle’s position, velocity or attitude.
I think to begin with this application you should choose how to implement the control system on your companion computer.
You can use different companion computer hardware and software to achieve your goal. For example you can use the ROS framework and write a custom ROS node to implement the control system and send the mavlink command to ArduPilot through MAVROS or you can use DroneKit to control ArduPilot using Python.

Thank you Luca for your reply and help.
I’m bachelor degree student and beginner in this topic and I don’t understand your mean of " how to implement the control system in your companion computer "
I have distance from object with good and high frequency for my application and I just need move to the object.
My question is, for this application Do I need to design a controller? or simply I can upload new distance data every time and go to new destination?

Regards

Hey Joe, sorry for the misunderstanding, first I thought you wanted to control the attitude, but for your application it’s much easier to just sent the position target. So you’re right, you just need to populate the SET_POSITION_TARGET_LOCAL_NED or the SET_POSITION_TARGET_GLOBAL_INT command with the target position and send it to AP.

1 Like

First of all Thank you Luca.
Do you know about this commands?
I read mavlink movement commands in guided mode you mentioned in your reply.
Can I send new message with new target data before moving of last message complete?
And final question, at what frequency can I send target data?

Regards

I think we need someone more expert about this topic. I’m sure sending a new movement command will override the previous one, so you shouldn’t encounter any issues if you keep updating the target location. By the way I’m not sure about the frequency limit, but I think it is not necessary to update the target location at a high frequency, because the drone linear position dynamic is quite slow. I don’t know about the dynamic of the moving target, but maybe it could be enough to update the target location at 1 Hz. If you acquire the target position at a higher frequency you could apply a digital filter before sending the mavlink message (moving average, median, …).

I also advice you to use SITL to simulate the drone behaviour on your computer. You could start by easily sending some movement command via MAVProxy (there are some examples in the documentation). You can also run your custom code to update the target location on your computer, so you can debug in a more convenient (and safe!) way on the simulated environment.

1 Like

Do not go over 10Hz. It usually has no benefits and might be counterproductive

1 Like

Can you explain more? What would be the counterproductive effects?

I have not tested myself, but the EKF might diverge. Test it for yourself, then you can decide if it brings benefits