Hello, guys. I have a big doubt about how the MAVLink command-long works inside ArduCopter.
I’ve created two new entries in the MAV_CMD enum inside commom.xml. Those entries are responsible for pausing/resuming a mission from buttons in Mission Planner.
In my old code, I had the following lines:
GCS_Mavlink.cpp - handleMessage()
switch (msg->msgid) {
// lots of stuff
case MAVLINK_MSG_ID_COMMAND_LONG: {
// some other stuff
switch(packet.command) {
// cases about other enum values
case MAV_CMD_PAUSE_MISSION:
case MAV_CMD_RESUME_MISSION:
result = MAV_RESULT_ACCEPTED;
break;
} // end of second switch
} // end of first case
} // end of first switch
commands_logic.cpp - start_command()
switch(cmd.id) {
// cases about other enum values
case MAV_CMD_PAUSE_MISSION:
do_pause_mission();
break;
case MAV_CMD_RESUME_MISSION:
do_resume_mission();
break;
} // end of switch
Well, this was not working. So, I tried inserting the methods do_pause_mission() and do_resume_mission() inside the code in the handleMessage() method, like this:
GCS_Mavlink.cpp - handleMessage()
switch (msg->msgid) {
// lots of stuff
case MAVLINK_MSG_ID_COMMAND_LONG: {
// some other stuff
switch(packet.command) {
// cases about other enum values
case MAV_CMD_PAUSE_MISSION:
copter.do_pause_mission();
result = MAV_RESULT_ACCEPTED;
break;
case MAV_CMD_RESUME_MISSION:
copter.do_resume_mission();
result = MAV_RESULT_ACCEPTED;
break;
} // end of second switch
} // end of first case
} // end of first switch
For my surprise, now it works. But that’s not how the tutorial presented in ArduPilot’s documentation teaches us to do it. In Step #5, although it mentions the GCS_Mavlink.cpp file, the tutorial says that, in order to create a new navigation command, we just need to add this new case to commans_logic.cpp along with some other stuff.
What I want to know is: why wasn’t it working before, and why is it now? What is the correct order of the calling stack of all those methods? And AP_Mission.cpp, what is its role in all of that? Am I now doing it in the correct way, or did I manage to make it work in the wrong way?
Thanks in advance for all the help!