mavros icon indicating copy to clipboard operation
mavros copied to clipboard

How to properly use /mavros/setpoint_raw/target_attitude?

Open reyes73a opened this issue 5 years ago • 16 comments

Hey guys,

I would like to learn how to properly use /mavros/setpoint_raw/target_attitude messages to command the FCU to a particular orientation angle.

Right now I create a mavros_msgs.AttitudeTarget and publish it to /mavros/setpoint_raw/target_attitude. Inside mavros_msgs.AttitudeTarget i specify a quaternion that defines roll,pitch and yaw. The message is publishing correctly and if I do rostopic echo /mavros/setpoint_raw/target_attitude i can see the values changing accordingly, but I do not see the aircraft reacting to these commands. What I am doing wrong/missing?

I got a few questions about this that could suggest why it is not working:

  1. mavros_msgs.AttitudeTarget contains both a setOrientation and setThrust. Do i have to set the thrust always? I am not currently.
  2. mavros_msgs.AttitudeTarget contains a few flags to ignore certain components such as IGNORE_ATTITUDE, IGNORE_PITCH_RATE, IGNORE_THRUST etc. How do I use these properly?
  3. So far my tests have been arming the drone (motor spinning) while holding it down on the ground. Then move around the sticks to make sure FCU reacts to commands and then sending the mavros_msgs.AttitudeTarget message. I had tried in STABILIZE, ALT_HOLD and LOITER while holding it down on the ground and it is still ignoring my commands. Do I have to be in a particular mode for this to work?
  4. I currently use: Frame: QUAD CubeBlack ArduCopter V3.7.0-dev

Will this firmware support this functionality?

Any help is greatly appreciated! Thanks!!!

reyes73a avatar Nov 21 '19 16:11 reyes73a

you can set type_mask to ignore certain components IGNORE_ATTITUDE, IGNORE_PITCH_RATE, IGNORE_THRUST. According to

uint8 IGNORE_ROLL_RATE = 1	# body_rate.x
uint8 IGNORE_PITCH_RATE = 2	# body_rate.y
uint8 IGNORE_YAW_RATE = 4	# body_rate.z
uint8 IGNORE_THRUST = 64
uint8 IGNORE_ATTITUDE = 128	# orientation field

you can set the last bit of type_mask to enable IGNORE_ROLL_RATE. And if you want to enable GNORE_ROLL_RATE and IGNORE_PITCH_RATE you can set the last 2 bits of type_mask to 011(binary) i.e. 3(decimal). The others are the same.

And you can set your drone to offboard mode to make it follow your commands.

zhenfu128 avatar Sep 02 '20 03:09 zhenfu128

I have not used Arducopter firmware much, but I believe your issue is that /mavros/setpoint_raw/target_attitude is feedback from the FCU. This tells you how the FCU is interpreting your commands. You should be sending commands to: /mavros/setpoint_raw/attitude.

PX4 has limits on what the firmware will accept as a valid input, otherwise it will just ignore you (off the top of my head):

  • To get attitude control: type_mask = IGNORE_ROLL_RATE | IGNORE_PITCH_RATE | IGNORE_YAW_RATE
  • To get "normal RC" control: type_mask = IGNORE_ROLL_RATE | IGNORE_PITCH_RATE
  • To get acro control: type_mask = IGNORE_ATTITUDE

I believe in all cases, you need to provide a thrust input, but I haven't double checked this, and ArduCopter may be different.

pryre avatar Mar 30 '21 22:03 pryre

In addition - always update header.stamp, keep updates frequent.

Also you need to set GUIDED mode for APM. https://ardupilot.org/dev/docs/copter-commands-in-guided-mode.html#copter-commands-in-guided-mode-set-attitude-target

vooon avatar Mar 31 '21 08:03 vooon

@reyes73a were you able to solve this problem? I am developing a project and i need to send yaw, pitch and roll commands to a fixed wing, could you help me?

joaoalves10 avatar Sep 24 '21 08:09 joaoalves10

I have not used Arducopter firmware much, but I believe your issue is that /mavros/setpoint_raw/target_attitude is feedback from the FCU. This tells you how the FCU is interpreting your commands. You should be sending commands to: /mavros/setpoint_raw/attitude.

PX4 has limits on what the firmware will accept as a valid input, otherwise it will just ignore you (off the top of my head):

* To get attitude control: `type_mask = IGNORE_ROLL_RATE | IGNORE_PITCH_RATE | IGNORE_YAW_RATE`

* To get "normal RC" control: `type_mask = IGNORE_ROLL_RATE | IGNORE_PITCH_RATE`

* To get acro control: `type_mask = IGNORE_ATTITUDE`

I believe in all cases, you need to provide a thrust input, but I haven't double checked this, and ArduCopter may be different.

Hi @pryre , did you try attitude control in PX4 fixed wing ? i am trying for a few days with setpoint_raw/attitude command to make the aircraft turn to a specific heading with the quarterion coordinates but it does not respond. The aircraft turns to OFFBOARD mode but just mantain its previous heading

joaoalves10 avatar Sep 24 '21 09:09 joaoalves10

Hi all, i was using /mavros/setpoint_raw/attitude topic to control attititude kept type_mask to 128 so that i can do attitude and thrust cntrol. I was able to do thrust control using PID but I have doubt in doing attitude control since i am trying to do global navigation along with attitude control. I am publishing global setpoints to mavros/setpoint_raw/global topic. Anyone have idea how to control attitude while doing global navigation also? Thanks in advance

rrajnidhi avatar Aug 09 '22 19:08 rrajnidhi

@rrajnidhi may I ask you how do you use PID to control thrust

Thomas000001 avatar Sep 08 '22 07:09 Thomas000001

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

joaoalves10 avatar Sep 08 '22 09:09 joaoalves10

do you try to control drone's attitude by pitch,roll,yaw and thrust

joaoalves10 @.***> 於 2022年9月8日 週四 下午5:27寫道:

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240462311, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYXSRTSLWJF3VZOEUW7G7PTV5GWQZANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

Thomas000001 avatar Sep 08 '22 09:09 Thomas000001

Only fixed wing drones.

Em qui., 8 de set. de 2022 às 10:36, Thomas000001 @.***> escreveu:

do you try to control drone's attitude by pitch,roll,yaw and thrust

joaoalves10 @.***> 於 2022年9月8日 週四 下午5:27寫道:

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub <https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240462311, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AYXSRTSLWJF3VZOEUW7G7PTV5GWQZANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240472268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMLLBMMU7GY2ZQU3LVYQZ3V5GXTTANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

joaoalves10 avatar Sep 08 '22 13:09 joaoalves10

Thank you. Do you try to control quadrotor aircraft’s attitude by pitch, roll and thrust, or have you used body rate to control attitude

joaoalves10 @.***>於 2022年9月8日 週四,下午9:45寫道:

Only fixed wing drones.

Em qui., 8 de set. de 2022 às 10:36, Thomas000001 @.***> escreveu:

do you try to control drone's attitude by pitch,roll,yaw and thrust

joaoalves10 @.***> 於 2022年9月8日 週四 下午5:27寫道:

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub <https://github.com/mavlink/mavros/issues/1356#issuecomment-1240462311 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AYXSRTSLWJF3VZOEUW7G7PTV5GWQZANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240472268, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AVMLLBMMU7GY2ZQU3LVYQZ3V5GXTTANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240739589, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYXSRTUG4PHRETDVRGYCP4TV5HUXBANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

Thomas000001 avatar Sep 08 '22 23:09 Thomas000001

I did not work with quadcopters, only with fixed wings.

Em sex., 9 de set. de 2022 às 00:54, Thomas000001 @.***> escreveu:

Thank you. Do you try to control quadrotor aircraft’s attitude by pitch, roll and thrust, or have you used body rate to control attitude

joaoalves10 @.***>於 2022年9月8日 週四,下午9:45寫道:

Only fixed wing drones.

Em qui., 8 de set. de 2022 às 10:36, Thomas000001 @.***> escreveu:

do you try to control drone's attitude by pitch,roll,yaw and thrust

joaoalves10 @.***> 於 2022年9月8日 週四 下午5:27寫道:

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240462311 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AYXSRTSLWJF3VZOEUW7G7PTV5GWQZANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub <https://github.com/mavlink/mavros/issues/1356#issuecomment-1240472268 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBMMU7GY2ZQU3LVYQZ3V5GXTTANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1240739589, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AYXSRTUG4PHRETDVRGYCP4TV5HUXBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1241347099, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMLLBNY2RUW4IESM4ATRK3V5J4DLANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

joaoalves10 avatar Sep 09 '22 09:09 joaoalves10

I got it. Thank you very much. You help me understand the things that I confused

joaoalves10 @.***>於 2022年9月9日 週五,下午5:11寫道:

I did not work with quadcopters, only with fixed wings.

Em sex., 9 de set. de 2022 às 00:54, Thomas000001 @.***> escreveu:

Thank you. Do you try to control quadrotor aircraft’s attitude by pitch, roll and thrust, or have you used body rate to control attitude

joaoalves10 @.***>於 2022年9月8日 週四,下午9:45寫道:

Only fixed wing drones.

Em qui., 8 de set. de 2022 às 10:36, Thomas000001 @.***> escreveu:

do you try to control drone's attitude by pitch,roll,yaw and thrust

joaoalves10 @.***> 於 2022年9月8日 週四 下午5:27寫道:

Hi

In my project i used a PI to control thrust. I used the velocity measurement and velocity setpoint (airspeed that i aimed to reach) to calculate the thrust.

A quinta, 8/09/2022, 08:55, Thomas000001 @.***> escreveu:

@rrajnidhi https://github.com/rrajnidhi may I ask you how do you use PID to control thrust

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240360681 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBJYVTAUNCVF27PJQGTV5GLYBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240462311 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AYXSRTSLWJF3VZOEUW7G7PTV5GWQZANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/mavlink/mavros/issues/1356#issuecomment-1240472268 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AVMLLBMMU7GY2ZQU3LVYQZ3V5GXTTANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub <https://github.com/mavlink/mavros/issues/1356#issuecomment-1240739589 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AYXSRTUG4PHRETDVRGYCP4TV5HUXBANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1241347099, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AVMLLBNY2RUW4IESM4ATRK3V5J4DLANCNFSM4JQE4HPA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1241714634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYXSRTXNPNIJ6WRJHUJG4X3V5L5MJANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

Thomas000001 avatar Sep 10 '22 14:09 Thomas000001

Hi,

I was able to do attitude control using setpoint_raw_attitude. I used quartenion coordinates

A terça, 9/08/2022, 20:13, Nidhi raj R @.***> escreveu:

Hi all, i was using /mavros/setpoint_raw/attitude topic to control attititude kept type_mask to 128 so that i can do attitude and thrust cntrol. I was able to do thrust control using PID but I have doubt in doing attitude control since i am trying to do global navigation along with attitude control. I am publishing global setpoints to mavros/setpoint_raw/global topic. Anyone have idea how to control attitude while doing global navigation also? Thanks in advance

— Reply to this email directly, view it on GitHub https://github.com/mavlink/mavros/issues/1356#issuecomment-1209775675, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMLLBOYFFJ7UMV5URD6SUTVYKUV7ANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.***>

joaoalves10 avatar Oct 11 '22 09:10 joaoalves10

i'm having a similar issue, if I set the bitmask to 128 to ignore attitude and only use rates i get no response, only throttle works. if i add a quaternion, regardless of the value, the vehicle will constantly yaw in the SIL. Can you post a code snippet of your working result?

MatthewFehl365 avatar Jul 28 '23 05:07 MatthewFehl365

Hi, I was able to do attitude control using setpoint_raw_attitude. I used quartenion coordinates A terça, 9/08/2022, 20:13, Nidhi raj R @.> escreveu: Hi all, i was using /mavros/setpoint_raw/attitude topic to control attititude kept type_mask to 128 so that i can do attitude and thrust cntrol. I was able to do thrust control using PID but I have doubt in doing attitude control since i am trying to do global navigation along with attitude control. I am publishing global setpoints to mavros/setpoint_raw/global topic. Anyone have idea how to control attitude while doing global navigation also? Thanks in advance — Reply to this email directly, view it on GitHub <#1356 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMLLBOYFFJ7UMV5URD6SUTVYKUV7ANCNFSM4JQE4HPA . You are receiving this because you commented.Message ID: @.> Can you share the code for how you control attitude? Thank you very much!

BBD82500 avatar Mar 03 '24 04:03 BBD82500