Skip to content

Commit

Permalink
Modify template model header files
Browse files Browse the repository at this point in the history
  • Loading branch information
JcZou committed Dec 5, 2023
1 parent daf933b commit 99cc14b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/model/control/template_controller/lib/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ typedef struct {

/* enum of PilotMode */
uint8_T reserved;

/* home position [x y h yaw], unit [m m m rad] */
real32_T home[4];
} FMS_Out_Bus;

#endif
Expand Down Expand Up @@ -185,6 +188,8 @@ typedef struct {
real_T lat_0;
real_T lon_0;
real_T alt_0;
real_T dx_dlat;
real_T dy_dlon;
real32_T x_R;
real32_T y_R;
real32_T h_R;
Expand Down
9 changes: 8 additions & 1 deletion src/model/fms/template_fms/lib/FMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct {

/* Operation channel 2 */
uint32_T cmd_2;
real32_T param[7];
} GCS_Cmd_Bus;

#endif
Expand Down Expand Up @@ -198,6 +199,8 @@ typedef struct {
real_T lat_0;
real_T lon_0;
real_T alt_0;
real_T dx_dlat;
real_T dy_dlon;
real32_T x_R;
real32_T y_R;
real32_T h_R;
Expand Down Expand Up @@ -231,7 +234,8 @@ typedef enum {
FMS_Cmd_Land,
FMS_Cmd_Return,
FMS_Cmd_Pause,
FMS_Cmd_Continue
FMS_Cmd_Continue,
FMS_Cmd_SetHome = 2000
} FMS_Cmd;

#endif
Expand Down Expand Up @@ -385,6 +389,9 @@ typedef struct {

/* enum of PilotMode */
uint8_T reserved;

/* home position [x y h yaw], unit [m m m rad] */
real32_T home[4];
} FMS_Out_Bus;

#endif
Expand Down
19 changes: 18 additions & 1 deletion src/model/ins/external_ins/lib/INS.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ typedef struct {

#endif

#ifndef DEFINED_TYPEDEF_FOR_External_Pos_Bus_
#define DEFINED_TYPEDEF_FOR_External_Pos_Bus_

typedef struct {
uint32_T timestamp;
uint32_T field_valid;
real32_T x;
real32_T y;
real32_T z;
real32_T phi;
real32_T theta;
real32_T psi;
} External_Pos_Bus;

#endif

#ifndef DEFINED_TYPEDEF_FOR_INS_Out_Bus_
#define DEFINED_TYPEDEF_FOR_INS_Out_Bus_

Expand All @@ -160,6 +176,8 @@ typedef struct {
real_T lat_0;
real_T lon_0;
real_T alt_0;
real_T dx_dlat;
real_T dy_dlon;
real32_T x_R;
real32_T y_R;
real32_T h_R;
Expand All @@ -169,7 +187,6 @@ typedef struct {
} INS_Out_Bus;

#endif

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/model/ins/template_ins/ins_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#include <INS.h>
#include <firmament.h>

/* External Position */
MCN_DEFINE(external_pos, sizeof(External_Pos_Bus));
/* INS output bus */
MCN_DEFINE(ins_output, sizeof(INS_Out_Bus));

/* Model information */
fmt_model_info_t ins_model_info;

Expand All @@ -35,6 +38,7 @@ void ins_interface_init(void)

/* advertise ins_output topic */
mcn_advertise(MCN_HUB(ins_output), NULL);
mcn_advertise(MCN_HUB(external_pos), NULL);

/* Add your code here */
}
18 changes: 18 additions & 0 deletions src/model/ins/template_ins/lib/INS.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ typedef struct {

#endif

#ifndef DEFINED_TYPEDEF_FOR_External_Pos_Bus_
#define DEFINED_TYPEDEF_FOR_External_Pos_Bus_

typedef struct {
uint32_T timestamp;
uint32_T field_valid;
real32_T x;
real32_T y;
real32_T z;
real32_T phi;
real32_T theta;
real32_T psi;
} External_Pos_Bus;

#endif

#ifndef DEFINED_TYPEDEF_FOR_INS_Out_Bus_
#define DEFINED_TYPEDEF_FOR_INS_Out_Bus_

Expand All @@ -160,6 +176,8 @@ typedef struct {
real_T lat_0;
real_T lon_0;
real_T alt_0;
real_T dx_dlat;
real_T dy_dlon;
real32_T x_R;
real32_T y_R;
real32_T h_R;
Expand Down
25 changes: 25 additions & 0 deletions src/model/plant/template_plant/lib/Plant.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@
extern "C" {
#endif

#ifndef DEFINED_TYPEDEF_FOR_Environment_Info_Bus_
#define DEFINED_TYPEDEF_FOR_Environment_Info_Bus_

/* Collision Information */
typedef struct {
uint32_T timestamp;

/* Hit point in NED frame */
real32_T hit_point[3];

/* Hit point normal */
real32_T hit_normal[3];

/* Hit location in NED frame */
real32_T hit_location[3];

/* External torque applied at body in body frame */
real32_T torque[3];

/* External force applied at body in body frame. */
real32_T force[3];
} Environment_Info_Bus;

#endif

#ifndef DEFINED_TYPEDEF_FOR_Control_Out_Bus_
#define DEFINED_TYPEDEF_FOR_Control_Out_Bus_

Expand Down
13 changes: 6 additions & 7 deletions src/task/comm/task_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,21 @@ static uint32_t get_custom_mode(FMS_Out_Bus fms_out)
bool mavlink_msg_heartbeat_pack_func(mavlink_message_t* msg_t)
{
mavlink_heartbeat_t heartbeat = { 0 };
FMS_Out_Bus fms_out;
FMS_Out_Bus fms_out = { 0 };

heartbeat.type = MAV_TYPE_QUADROTOR;
heartbeat.autopilot = MAV_AUTOPILOT_PX4;
heartbeat.base_mode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
heartbeat.custom_mode = 0;
heartbeat.system_status = MAV_STATE_STANDBY;

if (mcn_copy_from_hub(MCN_HUB(fms_output), &fms_out) != FMT_EOK) {
return false;
if (mcn_copy_from_hub(MCN_HUB(fms_output), &fms_out) == FMT_EOK) {
if (fms_out.status == VehicleStatus_Arm || fms_out.status == VehicleStatus_Standby) {
heartbeat.base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
heartbeat.system_status = MAV_STATE_ACTIVE;
}
}

if (fms_out.status == VehicleStatus_Arm || fms_out.status == VehicleStatus_Standby) {
heartbeat.base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
heartbeat.system_status = MAV_STATE_ACTIVE;
}
/* map fms mode to px4 ctrl mode */
heartbeat.custom_mode = get_custom_mode(fms_out);

Expand Down

0 comments on commit 99cc14b

Please sign in to comment.