diff --git a/README.md b/README.md index 54464a30..c2054b10 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -“无人战场伤员搬运”软件系统设计 +“智能伤员救助”软件系统设计 diff --git a/doc/“无人战场伤员搬运”软件系统的需求构思及描述.docx b/doc/“智能伤员感知救助”软件系统的需求构思及描述.docx similarity index 100% rename from doc/“无人战场伤员搬运”软件系统的需求构思及描述.docx rename to doc/“智能伤员感知救助”软件系统的需求构思及描述.docx diff --git a/doc/“无人战场伤员搬运”软件设计规格说明书.docx b/doc/“智能伤员感知救助”软件设计规格说明书.docx similarity index 100% rename from doc/“无人战场伤员搬运”软件设计规格说明书.docx rename to doc/“智能伤员感知救助”软件设计规格说明书.docx diff --git a/doc/“无人战场伤员搬运”软件需求规格说明书.docx b/doc/“智能伤员感知救助”软件需求规格说明书.docx similarity index 100% rename from doc/“无人战场伤员搬运”软件需求规格说明书.docx rename to doc/“智能伤员感知救助”软件需求规格说明书.docx diff --git a/model/“无人战场救援”软件需求模型.eddx b/model/“智能伤员感知救助”软件需求模型.eddx similarity index 100% rename from model/“无人战场救援”软件需求模型.eddx rename to model/“智能伤员感知救助”软件需求模型.eddx diff --git a/model/“无人战场救援”软件需求模型.vsdx b/model/“智能伤员感知救助”软件需求模型.vsdx similarity index 100% rename from model/“无人战场救援”软件需求模型.vsdx rename to model/“智能伤员感知救助”软件需求模型.vsdx diff --git a/src/无人机飞行控制代码/terminal_control.cpp b/src/无人机飞行控制代码/terminal_control.cpp new file mode 100644 index 00000000..e88ed59b --- /dev/null +++ b/src/无人机飞行控制代码/terminal_control.cpp @@ -0,0 +1,864 @@ +/*************************************************************************************************************************** +* terminal_control.cpp +* +* Author: Qyp +* +* Update Time: 2020.11.4 +* +* Introduction: test function for sending ControlCommand.msg +***************************************************************************************************************************/ +#include +#include + +#include +#include +#include +#include +#include + +#include "controller_test.h" +#include "KeyboardEvent.h" + + +//json数据库 +#include +#include +#include +#include +#include +#include +#include + +#define HOST "192.168.43.58" +#define PORT 1900 + +#define VEL_XY_STEP_SIZE 0.1 +#define VEL_Z_STEP_SIZE 0.1 +#define YAW_STEP_SIZE 0.08 +#define TRA_WINDOW 2000 +#define NODE_NAME "terminal_control" + +using namespace std; + +//即将发布的command +prometheus_msgs::ControlCommand Command_to_pub; +//轨迹容器 +std::vector posehistory_vector_; + + +float time_trajectory = 0.0; +// 轨迹追踪总时长,键盘控制时固定时长,指令输入控制可调 +float trajectory_total_time = 50.0; + + +//发布 +ros::Publisher move_pub; +ros::Publisher ref_trajectory_pub; +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 函数声明 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +void mainloop1(); +void mainloop2(); +void generate_com(int Move_mode, float state_desired[4]); +void Draw_in_rviz(const prometheus_msgs::PositionReference& pos_ref, bool draw_trajectory); +void timerCallback(const ros::TimerEvent& e) +{ + cout << ">>>>>>>>>>>>>>>> Welcome to use Prometheus Terminal Control <<<<<<<<<<<<<<<<"<< endl; + cout << "ENTER key to control the drone: " <>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 主函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +int main(int argc, char **argv) +{ + ros::init(argc, argv, "terminal_control"); + ros::NodeHandle nh; + + // 【发布】 控制指令 + move_pub = nh.advertise("/prometheus/control_command", 10); + + // 【发布】 参考轨迹 + ref_trajectory_pub = nh.advertise("/prometheus/reference_trajectory", 10); + + //用于控制器测试的类,功能例如:生成圆形轨迹,8字轨迹等 + Controller_Test Controller_Test; // 打印参数 + Controller_Test.printf_param(); + + // 初始化命令 - Idle模式 电机怠速旋转 等待来自上层的控制指令 + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Idle; + Command_to_pub.Command_ID = 0; + Command_to_pub.source = NODE_NAME; + Command_to_pub.Reference_State.Move_mode = prometheus_msgs::PositionReference::XYZ_POS; + Command_to_pub.Reference_State.Move_frame = prometheus_msgs::PositionReference::ENU_FRAME; + Command_to_pub.Reference_State.position_ref[0] = 0; + Command_to_pub.Reference_State.position_ref[1] = 0; + Command_to_pub.Reference_State.position_ref[2] = 0; + Command_to_pub.Reference_State.velocity_ref[0] = 0; + Command_to_pub.Reference_State.velocity_ref[1] = 0; + Command_to_pub.Reference_State.velocity_ref[2] = 0; + Command_to_pub.Reference_State.acceleration_ref[0] = 0; + Command_to_pub.Reference_State.acceleration_ref[1] = 0; + Command_to_pub.Reference_State.acceleration_ref[2] = 0; + Command_to_pub.Reference_State.yaw_ref = 0; + + //固定的浮点显示 + cout.setf(ios::fixed); + //setprecision(n) 设显示小数精度为n位 + cout<>>>>>>>>>>>>>>> Welcome to use Prometheus Terminal Control <<<<<<<<<<<<<<<<"<< endl; + cout << "Please choose the Remote Mode: 0 for command input control, 1 for keyboard input control"<> Remote_Mode; + + if (Remote_Mode == 0) + { + cout << "Command input control mode"<>>>>>>>>>>>>>>> Welcome to use Prometheus Terminal Control <<<<<<<<<<<<<<<<"<< endl; + cout << "Please choose the Command.Mode: 0 for Idle, 1 for Takeoff, 2 for Hold, 3 for Land, 4 for Move, 5 for Disarm, 6 for User_Mode1, 7 for User_Mode2"<> Control_Mode; + + if(Control_Mode == prometheus_msgs::ControlCommand::Move) + { + cout << "Please choose the Command.Reference_State.Move_mode: 0 for XYZ_POS, 1 for XY_POS_Z_VEL, 2 for XY_VEL_Z_POS, 3 for XYZ_VEL, 5 for TRAJECTORY"<> Move_mode; + + if(Move_mode == prometheus_msgs::PositionReference::TRAJECTORY) + { + cout << "For safety, please move the drone near to the trajectory start point firstly!!!"<> Trjectory_mode; + cout << "Input the trajectory_total_time:"<> trajectory_total_time; + }else + { + cout << "Please choose the Command.Reference_State.Move_frame: 0 for ENU_FRAME, 1 for BODY_FRAME"<> Move_frame; + cout << "Please input the reference state [x y z yaw]: "<< endl; + cout << "setpoint_t[0] --- x [m] : "<< endl; + cin >> state_desired[0]; + cout << "setpoint_t[1] --- y [m] : "<< endl; + cin >> state_desired[1]; + cout << "setpoint_t[2] --- z [m] : "<< endl; + cin >> state_desired[2]; + cout << "setpoint_t[3] --- yaw [du] : "<< endl; + cin >> state_desired[3]; + } + + } + else if(Control_Mode == prometheus_msgs::ControlCommand::User_Mode1) + { + cout << "Please choose the Command.Reference_State.Move_mode: 0 for XYZ_POS, 1 for XY_POS_Z_VEL, 2 for XY_VEL_Z_POS, 3 for XYZ_VEL, 5 for TRAJECTORY"<> state_desired[0]; + cout << "setpoint_t[1] --- y [m] : "<< endl; + cin >> state_desired[1]; + cout << "setpoint_t[2] --- z [m] : "<< endl; + cin >> state_desired[2]; + cout << "setpoint_t[3] --- yaw [du] : "<< endl; + cin >> state_desired[3]; + } + } + else if(Control_Mode == 999) + { + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Idle; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + Command_to_pub.Reference_State.yaw_ref = 999; + move_pub.publish(Command_to_pub); + Command_to_pub.Reference_State.yaw_ref = 0.0; + } + + switch (Control_Mode) + { + case prometheus_msgs::ControlCommand::Idle: + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Idle; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + move_pub.publish(Command_to_pub); + break; + + case prometheus_msgs::ControlCommand::Takeoff: + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Takeoff; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + move_pub.publish(Command_to_pub); + break; + + case prometheus_msgs::ControlCommand::Hold: + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Hold; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + move_pub.publish(Command_to_pub); + break; + + case prometheus_msgs::ControlCommand::Land: + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Land; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + move_pub.publish(Command_to_pub); + break; + + case prometheus_msgs::ControlCommand::Move: + if(Move_mode == prometheus_msgs::PositionReference::TRAJECTORY) + { + time_trajectory = 0.0; + + while(time_trajectory < trajectory_total_time) + { + Command_to_pub.header.stamp = ros::Time::now(); + Command_to_pub.Mode = prometheus_msgs::ControlCommand::Move; + Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1; + Command_to_pub.source = NODE_NAME; + + if(Trjectory_mode == 0) + { + Command_to_pub.Reference_State = Controller_Test.Circle_trajectory_generation(time_trajectory); + }else if(Trjectory_mode == 1) + { + Command_to_pub.Reference_State = Controller_Test.Eight_trajectory_generation(time_trajectory); + }else if(Trjectory_mode == 2) + { + Command_to_pub.Reference_State = Controller_Test.Step_trajectory_generation(time_trajectory); + }else if(Trjectory_mode == 3) + { + Command_to_pub.Reference_State = Controller_Test.Line_trajectory_generation(time_trajectory); + } + + move_pub.publish(Command_to_pub); + time_trajectory = time_trajectory + 0.01; + + cout << "Trajectory tracking: "<< time_trajectory << " / " << trajectory_total_time << " [ s ]" < 25 && time_trajectory <= 50){ + state_desired[1] += (time_trajectory-25)/5; + } + else if (time_trajectory > 50 && time_trajectory <= 75){ + state_desired[0] -= (time_trajectory-50)/5; + } + else if (time_trajectory > 75 && time_trajectory <= 100){ + state_desired[1] -= (time_trajectory-75)/5; + } + cout<<'x pos: '<>>>>>>>>>>>>>>> Welcome to use Prometheus Terminal Control <<<<<<<<<<<<<<<<"<< endl; + cout << "ENTER key to control the drone: " < TRA_WINDOW){ + posehistory_vector_.pop_back(); + } + + nav_msgs::Path reference_trajectory; + reference_trajectory.header.stamp = ros::Time::now(); + reference_trajectory.header.frame_id = "world"; + reference_trajectory.poses = posehistory_vector_; + ref_trajectory_pub.publish(reference_trajectory); + }else + { + posehistory_vector_.clear(); + + nav_msgs::Path reference_trajectory; + reference_trajectory.header.stamp = ros::Time::now(); + reference_trajectory.header.frame_id = "world"; + reference_trajectory.poses = posehistory_vector_; + ref_trajectory_pub.publish(reference_trajectory); + } +} \ No newline at end of file