New Flight Task - MyTask

Trying to follow the Flight Tasks (Flight Tasks | PX4 User Guide) Guide from the Docs.

But getting this error :
$ make px4_sitl jmavsim
[4/9] Building CXX object src/modules/…anager.dir/FlightTasks_generated.cpp.o
FAILED: src/modules/flight_mode_manager/CMakeFiles/modules__flight_mode_manager.dir/FlightTasks_generated.cpp.o
/bin/ccache /bin/c++ -DCONFIG_ARCH_BOARD_PX4_SITL -DENABLE_LOCKSTEP_SCHEDULER -DMODULE_NAME=“flight_mode_manager” -DPX4_MAIN=flight_mode_manager_app_main -D__CUSTOM_FILE_IO__ -D__PX4_LINUX -D__PX4_POSIX -D__STDC_FORMAT_MACROS -Dnoreturn_function=“attribute((noreturn))” -I…/…/boards/px4/sitl/src -I…/…/platforms/posix/src/px4/common/include -I. -Isrc/lib -I…/…/platforms/posix/src/px4/generic/generic/include -I…/…/platforms/common -I…/…/platforms/common/include -I…/…/src -I…/…/src/include -I…/…/src/lib -I…/…/src/lib/matrix -I…/…/src/modules -I…/…/platforms/posix/include -Iexternal/Install/include -I…/…/src/modules/flight_mode_manager -Isrc/modules/flight_mode_manager -I…/…/src/modules/flight_mode_manager/tasks/AutoFollowMe -I…/…/src/modules/flight_mode_manager/tasks/Auto -I…/…/src/modules/flight_mode_manager/tasks/FlightTask -I…/…/src/modules/flight_mode_manager/tasks/Utility -I…/…/src/lib/slew_rate -I…/…/src/lib/motion_planning -I…/…/src/modules/flight_mode_manager/tasks/AutoLineSmoothVel -I…/…/src/modules/flight_mode_manager/tasks/AutoMapper -I…/…/src/modules/flight_mode_manager/tasks/Descend -I…/…/src/modules/flight_mode_manager/tasks/Failsafe -I…/…/src/modules/flight_mode_manager/tasks/ManualAcceleration -I…/…/src/modules/flight_mode_manager/tasks/ManualAltitudeSmoothVel -I…/…/src/modules/flight_mode_manager/tasks/ManualAltitude -I…/…/src/modules/flight_mode_manager/tasks/ManualPosition -I…/…/src/modules/flight_mode_manager/tasks/ManualPositionSmoothVel -I…/…/src/modules/flight_mode_manager/tasks/Transition -I…/…/src/modules/flight_mode_manager/tasks/Orbit -I…/…/src/modules/flight_mode_manager/tasks/MyTask -O2 -g -DNDEBUG -fPIC -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Werror -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -fdiagnostics-color=always -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fcheck-new -fno-exceptions -fno-rtti -fno-threadsafe-statics -Wreorder -Wno-overloaded-virtual -Wno-cast-align -std=gnu++14 -MD -MT src/modules/flight_mode_manager/CMakeFiles/modules__flight_mode_manager.dir/FlightTasks_generated.cpp.o -MF src/modules/flight_mode_manager/CMakeFiles/modules__flight_mode_manager.dir/FlightTasks_generated.cpp.o.d -o src/modules/flight_mode_manager/CMakeFiles/modules__flight_mode_manager.dir/FlightTasks_generated.cpp.o -c src/modules/flight_mode_manager/FlightTasks_generated.cpp
src/modules/flight_mode_manager/FlightTasks_generated.cpp: In member function ‘FlightTaskIndex FlightModeManager::switchVehicleCommand(int)’:
src/modules/flight_mode_manager/FlightTasks_generated.cpp:125:26: error: ‘VEHICLE_CMD_DO_MYTASK’ is not a member of ‘vehicle_command_s’
125 | case vehicle_command_s::VEHICLE_CMD_DO_MYTASK :
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
[5/9] Building CXX object src/modules/mavlink/CMakeFiles/modules__mavlink.dir/mavlink_messages.cpp.o
ninja: build stopped: subcommand failed.
make: *** [Makefile:230: px4_sitl] Error 1

You need to add your command to vehicle_cmd.msg and rebuild

There are many commands in vehicle_command.msg and there are some value assigned to the commands like uint16 VEHICLE_CMD_DO_ORBIT = 34
What is this value and what value i have to assign to uint16 VEHICLE_CMD_DO_MYTASK ?

I’m just a beginner, so it would be great if you could direct me to the what documentation i should read for this matter.

That value corresponds to the value of the command enum given in the MAVLINK Common dialect. So assign your command a value that falls outside the range of common cmd enums which is anything above 40000. Are you planning to send your command from a gcs? Because then there is quite alot of other things you will have to do.

I really don’t know how to send MAVLink commands, at this point of time.
I was in the impression that I need to change some PARAMETER from the px4 cmd line for triggering a flight task, as they say in the Docs
I definitely have to read about MAVLink

You should be able to do it via the parameter, if that’s whats in those instructions. The VEHICLE_CMD* is internal and separate from the MAVLINK commands even though they mirror each other. Triggering it via a MAV_CMD* is another way of doing it.

I am sort of hanging around with this same issue. I did as per what the docs said to do, but in the end, there’s this thing exist.
“To test the flight task you need to run the vehicle with the task enabled. For the example above, this means setting the parameter MPC_POS_MODE to 5, taking off, and switching the vehicle to Position mode.” (here i don’t know where can i set the parameter). after i run mc_pos_control command in the jmavsim, it shows the error like “invalid command”. I don’t know what i have to do in this term. I am new to this environment, would be glad to give me some advice.
Also, what value should given to VEHICLE_CMD_DO_MYTASK=? But we have to add that in .msg file, if it is not there, right?

Hi,
I get some progress, I can build and switch to position mode but no message displayed.
In the top CMakeLists.txt I add MyTask to the flight_tasks_all :

if(NOT px4_constrained_flash_build)
	list(APPEND flight_tasks_all
		AutoFollowTarget
		Orbit
		MyTask
	)
endif()

then in the VehicleCommand.msg just after the line uint16 VEHICLE_CMD_DO_ORBIT = 34:

uint16 VEHICLE_CMD_DO_MYTASK = 35

then I build with make px4_sitl gazebo-classic

in the console I type commander takeoff then commander mode posctl but it returns

pxh> INFO  [tone_alarm] notify negative

instead of the PX4_INFO message.

I’ll appreciate any help