Direct Control by MavLink

I'm working on a project that consists on control my APM with visual studio c++ code. I did the first step: sending a hearthbeat message to APM and receive some parameters like yaw, pitch and roll. I can Arm and Desarm too.
My problem is: I want to send a command like "Turn 90 degrees to the left" or "turn right". I have tried to use diferent commands to direct control my copter like rc_channels_override,set_attitude_target,manual_control, but with no success. Here is a part of my code:

static void armSystem()
{
// mavlink_message_t msg;
Console::WriteLine("Arm");
mavlink_msg_command_long_send( MAVLINK_COMM_0,
apm_system,
apm_component, // uint8_t target_component
MAV_CMD_COMPONENT_ARM_DISARM, // uint16_t command,
1, // uint8_t confirmation,
1.0, // float param1,
0, // float param2,
0, // float param3,
0, // float param4,
0, // float param5,
0, // float param6,
0 // float param7)
);
}

static void disarmSystem()
{
// mavlink_message_t msg;
Console::WriteLine("Disarm");
mavlink_msg_command_long_send( MAVLINK_COMM_0,
apm_system,
apm_component, // uint8_t target_component
MAV_CMD_COMPONENT_ARM_DISARM, // uint16_t command,
1, // uint8_t confirmation,
0.0, // float param1,
0, // float param2,
0, // float param3,
0, // float param4,
0, // float param5,
0, // float param6,
0 // float param7)
);

}

static void raw_commands(int var)
{
raw_values raw;
//raw.r_yaw = 0.314 ;
//raw.x_pitch = 0;
//raw.y_roll = 0 ;
//raw.z_throttle = 0.3;


switch(var)
{
case RIGHT:
{
mavlink_msg_rc_channels_override_send(MAVLINK_COMM_0, apm_system, apm_component, 0, 0, 1300, 0, 0, 0, 0, 0);
//Console::WriteLine("Right");
//const float q0[4]={0.70710678,-0.70710678,0.0,0.0};
////raw.r_yaw = apm_yaw - 90;
////raw.x_pitch = apm_pitch;
////raw.y_roll = apm_roll;
////raw.z_throttle = 10;
////raw.buttons = 0;
////if(raw.r_yaw < -180)
////{
//// raw.r_yaw = 360 + raw.r_yaw;
////}
//mavlink_msg_set_attitude_target_send(MAVLINK_COMM_0,apm_time_boot,apm_system,apm_component,0,q0,raw.y_roll,raw.x_pitch,raw.r_yaw,raw.z_throttle);
}
break;
case LEFT:
{
// Console::WriteLine("Left");
// const float q1[4]={0.70710678,0.70710678,0.0,0.0};

// //raw.r_yaw = apm_yaw + 90;
// //raw.x_pitch = apm_pitch;
// //raw.y_roll = apm_roll;
// //raw.z_throttle = 10;
// //raw.buttons = 0;
// //if(raw.r_yaw > 180)
// //{
// // raw.r_yaw = raw.r_yaw - 360;
// //}
// mavlink_msg_set_attitude_target_send(MAVLINK_COMM_0,apm_time_boot,apm_system,apm_component,0,q1,raw.y_roll,raw.x_pitch,raw.r_yaw,raw.z_throttle);
}
break;
case FRONT:
{
}
break;
case BACK:
{
}
break;
default:
break;
}


//mavlink_msg_manual_control_send(MAVLINK_COMM_0, apm_system, raw.x_pitch, raw.y_roll, raw.z_throttle, raw.r_yaw, raw.buttons);
}

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • @Lucas,

    I am interested in alike solution to build MAVLink client in  Javascript to be run

    from webpage GUI in HTML5.0 to control a robot.

    Basic Ground Control Station run from webpage to control a robot remotely

    and display response as oveerlay graphics.

    Are you aware of any implementation of MAVLink client in Javascript ?

  • What are you using to communicate with your APM? A Raspberry Pi?

    • No, I'm sending data through the serial port of my Windows via Xbees.  

    • Lucas, any update on this topic? I'm trying todo same stuff with my computer so I could end up sending mavlink messages from another arduino. 

This reply was deleted.