I have a pixhawk that is receiving telemetry messages from my laptop via a serial port. I send the message like so:
int MAVLinkIF::SendAttitudeTarget()
{
// basic messaging set up
mavlink_message_t msg;
int len;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
// packing inputs
uint8_t this_sys_id = 2;
uint8_t this_comp_id = 1;
uint8_t target_sys_id = 1;
uint8_t target_comp_id = 1;
uint32_t time_boot_ms = (uint32_t) get_time_usec();
uint8_t mask = 0; // Bitfield for ignoring input of
const float quarter[4] = {1, 0, 0, 0}; // quarternion for zero rotation
float body_roll_rate = 0; // no roll rate
float body_pitch_rate = 0; // no pitch rate
float body_yaw_rate = 0; // no yaw rate
float thrust = 0.10; // give it ten percent of thrust
mavlink_msg_set_attitude_target_pack(this_sys_id,this_comp_id,&msg,time_boot_ms,target_sys_id,
target_comp_id,mask,&(quarter[0]),body_roll_rate,body_pitch_rate,body_yaw_rate,thrust);
len = mavlink_msg_to_send_buffer(buf,&msg);
Write(len,(char*)(buf));
return 0;
}
where Write is just a function that sends data to the serial port. I get no response from the Pixhawk even though I'm sure the message is being sent to the Pixhawk. I am receiving the message like so:
nt MAVLinkIF::ParseMessage(char* msg, int bytes)
{
// COMMUNICATION THROUGH EXTERNAL UART PORT (XBee serial)
int bytes_processed = 0;
int channel = 0; // Channel parsing from
while(bytes_processed < bytes)
{
uint8_t c = msg[bytes_processed];
// Try to get a new message
if(mavlink_parse_char(channel, c, &mMavMsg, &mMavMsgStatus)) {
// Handle message if one can be read
switch(mMavMsg.msgid)
{
case MAVLINK_MSG_ID_SET_ATTITUDE_TARGET: // ID: 82
{
mavlink_set_attitude_target_t target;
mavlink_msg_set_attitude_target_decode(&mMavMsg, &target);
}
break;
case MAVLINK_MSG_ID_ATTITUDE_TARGET: // ID: 83
{
mavlink_attitude_target_t target;
mavlink_msg_attitude_target_decode(&mMavMsg, &target);
}
default:
//Do nothing
break;
}
} else if (mMavMsgStatus.parse_state == MAVLINK_PARSE_STATE_GOT_BAD_CRC1)
{
// if the message cannot be parsed due to a bad CRC
mPacketDrops += 1;
}
bytes_processed++;
}
return 0;
}
Any ideas? Am I using MAVLink correctly? I can provide additional information ASAP if needed.
Replies
Hi
I have the same issue. Did you solve it or not yet?
Thanks