Mavros setpoint_raw/attitude

The attitude should be specified in NED OR body frame for offboard control?

1 Like

The setpoint_raw/attitude uses NED as attitude while the setpoint_attitude/attitude topic uses ENU

2 Likes

In the topic, \mavros\local_position\pose, are the quaternions in body frame or NED frame? I am not sure whether this question makes sense, but I am not able to control the quadcopter by specifying the attitude in NED frame!

@BossHater Is there a reason you are using the topic local_position\pose? You will not be able to control the attitude with that topic.

I thought this thread was from your question on controlling the aircraft with setpoint_raw/attitude ?

You can look at which topics correspond to which from the mavros wiki

I am using \mavros\local_position\pose to read the current position of the copter. I have a guidance algorithm in place which publishes attitude and thrust to setpoint_raw\attitude.

I found the following code in mavros package, file setpoint_raw.cpp.
Doesn’t this mean that we have to supply the attitude in ENU frame?

void attitude_cb(const mavros_msgs::AttitudeTarget::ConstPtr &req)
{
double thrust_scaling;
Eigen::Quaterniond desired_orientation;
Eigen::Vector3d baselink_angular_rate;
Eigen::Vector3d body_rate;
double thrust;

  // Set Thrust scaling in px4_config.yaml, setpoint_raw block.
  // ignore thrust is false by default, unless no thrust scalling is set or thrust is zero
  auto ignore_thrust = req->thrust != 0.0 && !sp_nh.getParam("thrust_scaling", thrust_scaling);
  if (ignore_thrust) {
  	// I believe it's safer without sending zero thrust, but actually ignoring the actuation.
  	ROS_FATAL_THROTTLE_NAMED(5, "setpoint_raw", "Recieved thrust, but ignore_thrust is true: "
  		"the most likely cause of this is a failure to specify the thrust_scaling parameters "
  		"on px4/apm_config.yaml. Actuation will be ignored.");
  	return;
  } else {
  	if (thrust_scaling == 0.0) {
  		ROS_WARN_THROTTLE_NAMED(5, "setpoint_raw", "thrust_scaling parameter is set to zero.");
  	}
  	thrust = std::min(1.0, std::max(0.0, req->thrust * thrust_scaling));
  }
  // Take care of attitude setpoint
  desired_orientation = ftf::to_eigen(req->orientation);
  // Transform desired orientation to represent aircraft->NED,
  // MAVROS operates on orientation of base_link->ENU
  auto ned_desired_orientation = ftf::transform_orientation_enu_ned(
  	ftf::transform_orientation_baselink_aircraft(desired_orientation));
  body_rate = ftf::transform_frame_baselink_aircraft(
  	ftf::to_eigen(req->body_rate));
  set_attitude_target(
  			req->header.stamp.toNSec() / 1000000,
  			req->type_mask,
  			ned_desired_orientation,
  			body_rate,
  			thrust);

}

Hello @Jaeyoung-Lim !
According to Q ground control, the setpoint_raw/att is in ENU frame. However the pitch _ sp, roll_sp are in NED frame in Q Ground control.

I did the following test:
+ve roll_des in my code ------(I got)—> -ve local_position x NED

instead of :
+ve roll_des in my code ---------> +ve local_position y NED

Clearly, setpoint_raw/att is in ENU frame. Additionally MAVROS Wiki doesn’t mention the frame for this topic. It has highlighted few topics which use NED frame, but not this one. Please correct me if I am wrong. I wanted to confirm this with you to get clear understanding of the frames. Thanks much !

I think it is body frame and belongs to ENU