MCPcopy Create free account
hub / github.com/amov-lab/Prometheus / mainloop2

Function mainloop2

Modules/control/src/Utilities/terminal_control.cpp:287–625  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void mainloop2()
288{
289 KeyboardEvent keyboardcontrol;
290 Controller_Test Controller_Test;
291
292 char key_now;
293 char key_last;
294
295 cout << ">>>>>>>>>>>>>>>> Welcome to use Prometheus Terminal Control <<<<<<<<<<<<<<<<"<< endl;
296 cout << "ENTER key to control the drone: " <<endl;
297 cout << "1 for Arm, Space for Takeoff, L for Land, H for Hold, 0 for Disarm, 8/9 for Trajectory tracking" <<endl;
298 cout << "Move mode is fixed (XYZ_VEL,BODY_FRAME): w/s for body_x, a/d for body_y, k/m for z, q/e for body_yaw" <<endl;
299 cout << "CTRL-C to quit." <<endl;
300
301 while (ros::ok())
302 {
303 keyboardcontrol.RosWhileLoopRun();
304 key_now = keyboardcontrol.GetPressedKey();
305 switch (key_now)
306 {
307
308 //悬停, 应当只发送一次, 不需要循环发送
309 case U_KEY_NONE:
310
311 if (key_last != U_KEY_NONE)
312 {
313 //to be continued.
314 }
315 sleep(0.5);
316
317 break;
318
319 // 数字1(非小键盘数字):解锁及切换到OFFBOARD模式
320 case U_KEY_1:
321 cout << " " <<endl;
322 cout << "Arm and Switch to OFFBOARD." <<endl;
323
324 Command_to_pub.header.stamp = ros::Time::now();
325 Command_to_pub.Mode = prometheus_msgs::ControlCommand::Idle;
326 Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1;
327 Command_to_pub.source = NODE_NAME;
328 Command_to_pub.Reference_State.yaw_ref = 999;
329 move_pub.publish(Command_to_pub);
330 sleep(1.0);
331 break;
332
333 // 空格:起飞
334 case U_KEY_SPACE:
335 cout << " " <<endl;
336 cout << "Switch to Takeoff Mode." <<endl;
337
338 Command_to_pub.header.stamp = ros::Time::now();
339 Command_to_pub.Mode = prometheus_msgs::ControlCommand::Takeoff;
340 Command_to_pub.Command_ID = Command_to_pub.Command_ID + 1;
341 Command_to_pub.Reference_State.yaw_ref = 0.0;
342 Command_to_pub.source = NODE_NAME;
343 move_pub.publish(Command_to_pub);
344

Callers 1

mainFunction · 0.85

Calls 5

GetPressedKeyMethod · 0.80
Draw_in_rvizFunction · 0.70
RosWhileLoopRunMethod · 0.45

Tested by

no test coverage detected