로봇에게 목표 지점을 찍어주고, 해당 목표지점으로 네비게이션 명령을 내려주기위해 move_base_simple/goal(geometry_msgs/PoseStamped Message)
토픽을 이용했다.
/move_base_simple/goal
토픽으로 publish
명령을 통해 전송하여 네비게이션 명령을 내린다.private static WebSocketMessage<String> createRobotNavigationMessage(Location location) {
JSONObject position = new JSONObject();
position.put("x", location.getPositionX());
position.put("y", location.getPositionY());
position.put("z", location.getPositionZ());
JSONObject orientation = new JSONObject();
orientation.put("x", location.getOrientationX());
orientation.put("y", location.getOrientationY());
orientation.put("z", location.getOrientationZ());
orientation.put("w", location.getOrientationW());
JSONObject pose = new JSONObject();
pose.put("position", position);
pose.put("orientation", orientation);
JSONObject header = new JSONObject();
header.put("frame_id", "map");
JSONObject msg = new JSONObject();
msg.put("op", "publish");
msg.put("topic", "/move_base_simple/goal");
msg.put("msg", new JSONObject().put("header", header).put("pose", pose));
return new TextMessage(msg.toString());
}
WebSocketMessage<String> navigationMessage = createRobotNavigationMessage(location);
session.sendMessage(navigationMessage);
/move_base/status(actionlib_msgs/GoalStatusArray)
토픽만을 구독하여 상태를 확인하는 경우, 이전 네비게이션의 기록이 남아 있어 현재 진행 중인 네비게이션 작업이 뭔지 파악하기 어렵다. 따라서, /move_base/goal(move_base_msgs/MoveBaseActionGoal)
토픽에서 goal_id
를 가져와서 현재 네비게이션 목표를 식별할 수 있게 구현했다.
상태가 1이면, 새로운 네비게이션 목표가 설정된 것을 나타낸다. 하나의 로봇은 하나의 네비게이션만 수행할 수 있으므로 새로운 네비게이션이 목표 설정되어 상태가 1인 경우, 현재 진행중인 네비게이션이므로 이 목표의 goal_id를 저장한다. 상태가 3일 때는 목표에 도착한 것을 의미하며, 상태가 3이고, 저장한 goal_id와 일치하면, 네비게이션이 완료된 것이다. 이후 sseEmitters로 이벤트를 호출하여 프론트에게 배달 완료를 알린다.