AI/ROS2

[ROS2] Service ์‹ค์Šต(Call-And-Response)

์ดํƒœํ™ 2024. 4. 18. 00:59

๐Ÿค– Service

 

์•„๋ž˜ ๋งํฌ์˜ demo_nodes_cpp ํŒจํ‚ค์ง€์˜ ๋‚ด์šฉ๋“ค์„ ์ฐธ๊ณ ํ•˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

 

https://github.com/ros2/demos

 

GitHub - ros2/demos

Contribute to ros2/demos development by creating an account on GitHub.

github.com

 

์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด add_two_ints_server ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

 

service ๊ด€๋ จ commands๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์‹คํ–‰์ค‘์ธ ROS2 ๋…ธ๋“œ์˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์„œ๋น„์Šค์˜ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

์ดํ›„ ์ง€์ •๋œ ์„œ๋น„์Šค์˜ ํƒ€์ž…์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.

 

/add_two_ints ์„œ๋น„์Šค์˜ ํƒ€์ž…์€ example_interfaces/srv/AddTwoInts ์ด๋ฉฐ ํ•ด๋‹น ์„œ๋น„์Šค๋Š” ๋‘ ๊ฐœ์˜ int64 ํƒ€์ž…์˜ ์ž…๋ ฅ ('a', 'b')๋ฅผ ๋ฐ›์•„๋“ค์ด๊ณ  int64 ํƒ€์ž…์˜ ์ถœ๋ ฅ 'sum'์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ฆ‰, ๋‘ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ๊ทธ ํ•ฉ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.