unl-nimbus-lab / Freyja

High-level nonlinear state-space flight control for multirotors. Freyja is suitable for vehicles that already have a stabilizing autopilot.
GNU General Public License v3.0
14 stars 9 forks source link

rpyt_command has hardcoded control mode. #17

Closed hildebrandt-carl closed 2 years ago

hildebrandt-carl commented 2 years ago

Hi,

I was looking through some of Freyjas code and noticed that the rpyt_command was hard coded to always have a ctrl_mode of 0b00001111. More specifically in lqr_control_bias.cpp line 253-259:

  freyja_msgs::CtrlCommand ctrl_cmd;
  ctrl_cmd.roll = roll;
  ctrl_cmd.pitch = pitch;
  ctrl_cmd.yaw = yaw;
  ctrl_cmd.thrust = T;
  ctrl_cmd.ctrl_mode = 0b00001111;
  atti_cmd_pub_.publish( ctrl_cmd );

I was wondering if this was intentional. If not would you like me to push submit a change where the control mode is updated based on the messages from /mavros/state topic?

hildebrandt-carl commented 2 years ago

For example, pull request #18 should solve this. Let me know what you think.

ajshank commented 2 years ago

Thanks, @hildebrandt-carl. The ctrl_mode variable is currently poorly defined. It is designed to mark which controllable elements are being worked on - in this case, the fields represent [x x x x r p y t] (first four bits unused). This is a remnant from AscTec days, where it was possible to work entirely on individual "axes". See the message definition for what the intention currently is (although not implemented correctly). A good use for this field is to specify what some of outputs from the controller mean. For instance, since ArduPilot/PX4 supports sending yaw or yaw-rate, ctrl_mode can specify how to interpret the yaw field (yaw-rate is better indoors, while yaw may be sometimes preferable outdoors).

Note that any use of this field is disjoint from the autopilot/robot modes. The problem with your PR #18 is that it introduces a "loop", as well as a dependency on mavros. A more suitable debug message, FreyjaStatus, is already defined here, and should be used in the interface nodes in autopilot_handler. Additionally, as noted in this message, it should not be used inside Freyja's nodes to trigger state machine transitions.

hildebrandt-carl commented 2 years ago

Thanks for the info. Not sure I fully understand its purpose, but if its a remnant from AscTec days I understand the want for keeping it. I will start using FreyjaStatus or mavros/state from now on when determine which mode I am in.