Hello,
I am trying to implement a closed loop hover control using setpoint_attitude/attitude (I know I can directly use set_point/position/local, but this is not what I want). After the get the control command from feedback and goal position, I can get desired roll pitch, yaw and thrust. However, when transformation the roll pitch yaw into quaternion so that px4 can accept the signal. I am confused what transformation should I use? I googled it seems for different transformation sequence or method, the equation to get the quaterniion is different. And in tf2::Quarternion, there are several methods, ie, setRPY, setEulerZYX. I am wondering which one should I use. (I did directly use the roll pitch yaw to control Crazyflie before, but for px4 seems I need to transform angles to quaternion).
Thanks for your time!
@Haijie_Zhang You can use my personal project as reference. https://github.com/Jaeyoung-Lim/mavros_controllers This sends the body angular rates and thrust as a command. Most of the transformation is implemented inside geometric_controller
Hi Jaeyoung,
I have several more questions.
-
Is there a reason you use angular rates instead of desired roll pitch yaw to do this?
-
I saw there is a function
quaternion acc2quaternion(acceleration, yaw)
. Does that mean after I get aceleration from my own PID controller, I directly use directly use this function to get the desired quaternion angle? Then I can pub this quaternion angle tosetpoin_attitude/attitude
? -
If question 2 is correct, what should I use for
cmd_att.pose.position.x y z
as shown in your post? https://404warehouse.net/2015/12/20/autopilot-offboard-control-using-mavros-package-on-ros/
My understanding is that px4 wouldn’t use these three position values since it is the attitude control, only concentrate on the attitude values. Is it correct? -
From your answer this post, https://discuss.px4.io/t/trajectory-following-via-acceleration-setpoints-which-controller-to-use/7106, it seems I can directly use three desired accelerations to control the quad with
setpoint_accel/accel
. Is it correct? (Actually my desired attitude and thrust is calculated from desired accelerations based on the flatness equation). If yes, it would simplify my work.
Thanks for your time.
-
Heading is one of the states that are inaccurate and hard to obtain on real vehicles. Also it is something that does not need to be too accurate for trajectory tracking. Using rates make the planner be more resilient for these kind of uncertainties
-
Yes
-
You can set the type mask depending on what setpoint you want to send
-
I am not sure what the status is with acceleration setpoints. It would depend on your implementation how reliable it is since you can’t input jerk to the system
Hi Jaeyoung-Lim,
Sorry that I have more questions came up.
-
I tried to implement the setpoint_accel controller and it seems difficult to tune. I searched and found the acceleration control is not closed on px4. I guess that is the reason why there is almost no project based on this control method.
-
When using
setpoing_raw/attitude
, according to your codepubRateCommands
, you set themsgs.type_mask = 128
, which means you only need angular rates and thrust to do the control. I understand this together with the paper you mentioned. But when I want to only use angle setpoints and thrust to control this. It seems impossible becase themsgs.type_mask
can only be set to1, 2 or 4
. I cann’t block all the angular rates at the same time. So sending attitude_setpoint and thrust is impossible. Is my understanding corret? -
If use
setpoint_attitude/attitude
andsetpoint_attitude/thrust
to control it, I have to cope with thepose.positoin.x, y ,z
, since there is no suchmsgs.type_mask
inPoseStamped
. Which means I have to send position, attitude and thrust to control it. Is it correct? Or I can just leave theposition.x, y z
blank?
Because I don’t want position feedback used in my real MAV project(I will use images to calculate the desired attitudes), the only way is to send angular rates
and thrust
. Also, I need to change the controller implementation using images based on the paper you mentioned.
2, 3 those are both bitmasks you can mask whatever you want
I didn’t figure out how to set the type_mask
correctly. It should be something like type_mask = IGNORE_ROOL_RATE | IGNORE_PITCH_RATE | IGNORE_YAW_RATE
Thanks for your explanation.
@Haijie_Zhang https://github.com/mavlink/mavros/blob/master/mavros/src/plugins/setpoint_trajectory.cpp#L157
Is there a way to implement this mask using offboard mode in ROS? I don’t quite understand how to mix the position and attitude control with the mask. From what I understand you can select either position or attitude mode in Offboard mode, but can’t do both Offboard Mode (Generic/All Frames) | PX4 Guide (main) . Is there way to do the masking you described with ROS2 offboard?
@px4_robot You cannot mix position and attitude, since they are not independently controllable.
@Jaeyoung-Lim . Thanks for your reply. Can you tell me if my understanding is correct for these two points?
(1) You cannot mix position and attitude in offboard mode
(2) You can send a setpoint for attitude with a setpoint for altitude (z) with mavsdk (and mavros?) if you use the correct type_mask?
After reading your comment from Feb 2020 and the above comment I got hope for point #2. Am I understanding your post and the linked discussion correctly?
@px4_robot Nope you cannot send altitude and attitude at the same time. Position and attitude are two different controllers and you cannot independently control both at the same time.