Tianzhu
November 14, 2023, 6:01am
1
I have a module defined as below. In the shell, I can run “myModule stop/start” to restart the module. Is there a way to do it with code (e.g., in a mavlink message, I want to restart myModule)? Thanks!
class myModule: public ModuleBase<myModule>, public ModuleParams, public px4::ScheduledWorkItem {
}
Tianzhu
November 14, 2023, 5:51pm
2
Looks like we may be able to send the command to the main px4 instance (server) via socket.
}
int
Server::start()
{
std::string sock_path = get_socket_path(_instance_id);
// Delete socket in case it exists already.
unlink(sock_path.c_str());
_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (_fd < 0) {
PX4_ERR("error creating socket");
return -1;
}
sockaddr_un addr = {};
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, sock_path.c_str(), sizeof(addr.sun_path) - 1);
And the doc also mentions that. But I couldn’t find some example how to send such command from a client.
The server listens on a socket, to which clients can connect and send a command. The server then sends the output and return code back to the client
PX4 is the Professional Autopilot. Developed by world-class developers from industry and academia, and supported by an active world wide community, it powers all kinds of vehicles from racing and cargo drones through to ground vehicles and...
You can do system
calls to run other commands.
I’ve just done that here: Add I2C driver launcher by julianoes · Pull Request #22047 · PX4/PX4-Autopilot · GitHub
And note that it also requires some px4board and defconfig changes. It’s all in the pull request.
Tianzhu
November 14, 2023, 9:01pm
4
Thanks for the reply, @JulianOes . Do you mean something like this?
system("/opt/px4/bin/px4-muModule stop");
system("/opt/px4/bin/px4-muModule start");
Oh, my PR is for the Pixhawks, so NuttX based. For SITL on Linux it might look somewhat like what you suggest, as long as you have the paths right.
Tianzhu
November 14, 2023, 9:32pm
6
Got it, thank you so much, @JulianOes !