sudo apt-get install ros-noetic-rosbridge-server
soruce /opt/ros/noetic/setup.bash
roslaunch rosbridge_server rosbridge_websocket.launch
hostname -I
# ws://192.168.64.3:9090
[ROS] ROS Bridge - RosBridge의 정의와 Protocol 탐구
[ROS] ROS Bridge - RosBridge의 정의와 Protocol 탐구
자바 스프링 서버에서 ROS Bridge 서버로 연결해서 통신하는 코드이다.
private static WebSocketMessage<String> createWebSocketMessage() {
JSONObject position = new JSONObject();
position.put("x", -2.0);
position.put("y", 0.5);
position.put("z", 0.0);
JSONObject orientation = new JSONObject();
orientation.put("x", 0);
orientation.put("y", 0);
orientation.put("z", 0);
orientation.put("w", 1);
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());
}
@PostMapping("/control")
public ResponseEntity<String> controlRobot() {
try {
WebSocketClient client = new StandardWebSocketClient();
WebSocketSession session = client.execute(new RobotWebSocketHandler(), "ws://192.168.64.5:9090").get();
WebSocketMessage<String> webSocketMessage = createWebSocketMessage();
session.sendMessage(webSocketMessage);
return new ResponseEntity<>("Message sent to ROS system", HttpStatus.OK);
} catch (Exception e) {
log.error(e.getMessage());
return new ResponseEntity<>("Failed to send message", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
패키지 안 찾아질때
source /opt/ros/noetic/setup.bash