Hi @g.rousseau !
I’d like to compute the stereo camera pitch in the best possible way using the NED start vector basis.
The quaternion q is in the NED start vector basis.
Here is the code :
What’s in the guidance mode :
void SetStereoCam::enter()
{
target_pitch = 0.f; // degrees
}
void SetStereoCam::beginStep()
{
mTlmConsumer->getSample(NULL, telemetry::Method::TLM_LATEST);
}
void SetStereoCam::generateDroneReference()
{
guidance::Output *output = getOutput();
lockFrontCam(output);
resetVerticalVelocity(output);
setStereoCamPitch(output, target_pitch);
}
void SetStereoCam::correctDroneReference()
{
// send a msg if pitch reached at +-5 degrees
if (target_pitch*M_PI/180.f-0.09.f < pitch && pitch < target_pitch*M_PI/180.f+0.09.f)
{
const ::google::protobuf::Empty message;
msg_evt_sender.pitchReached(message);
}
}
Where the function setStereoCamPitch() is :
void setStereoCamPitch(guidance::Output *output, float pitch)
{
pitch = pitch*M_PI/180.f;
output->mHasStereoCamReference = true;
output->mStereoCamReference.mutable_pitch()->set_ctrl_mode(CamController::Messages::ControlMode::Enum::POSITION);
output->mStereoCamReference.mutable_pitch()->set_frame_of_ref(CamController::Messages::FrameOfReference::Enum::NED_START);
output->mStereoCamReference.mutable_pitch()->set_position(pitch);
}
The variable pitch (used in the if statement) is computed in a service and then shared through telemetry data :
float pitch = asin(2.f*(input->quaternions.q_w*input->quaternions.q_y - input->quaternions.q_z*input->quaternions.q_x));
with :
static const struct tlm_reg_field s_tlm_data_in_fields[] = {
TLM_REG_FIELD_SCALAR_EX(struct tlm_data_in, quaternions.q_w,
"orientation_ned_start_q.w", TLM_TYPE_FLOAT32),
TLM_REG_FIELD_SCALAR_EX(struct tlm_data_in, quaternions.q_x,
"orientation_ned_start_q.x", TLM_TYPE_FLOAT32),
TLM_REG_FIELD_SCALAR_EX(struct tlm_data_in, quaternions.q_y,
"orientation_ned_start_q.y", TLM_TYPE_FLOAT32),
TLM_REG_FIELD_SCALAR_EX(struct tlm_data_in, quaternions.q_z,
"orientation_ned_start_q.z", TLM_TYPE_FLOAT32),
};
static const struct tlm_reg_field s_tlm_data_out_fields[] = {
TLM_REG_FIELD_SCALAR(struct tlm_data_out, algo.pitch,
TLM_TYPE_FLOAT32),
};
I’d like to know if it’s better to compute the pitch in the guidance mode or not. I need the transition triggered by the message pitchReached to be the more accurate as possible 
Thank you,
Eliott