초보자를 위한 ROS : ROS란 무엇인가

SoYu·2022년 5월 6일
1

ROS

목록 보기
1/3
post-thumbnail

1. 서론 : ROS란 무엇인가

The Robot Operating System (ROS) is a set of software libraries and tools that help you build robot applications. From drivers to state-of-the-art algorithms, and with powerful developer tools, ROS has what you need for your next robotics project. And it's all open source.

위에 있는 내용은 ROS 공식 홈페이지에 있는 ROS에 대한 설명이다.

해석하자면 로봇 프로그래밍을 위한 라이브러리와 도구들의 모음이라는 뜻인데 로봇 프로그래밍 자체가 처음이라면 의미가 바로 이해될리가 없다.


로봇 운영체제(ROS,Robot Operating System)는 로봇 응용 프로그램을 개발할 때 필요한 하드웨어 추상화, 하위 디바이스 제어, 일반적으로 사용되는 기능의 구현, 프로세스간의 메시지 패싱, 패키지 관리, 개발환경에 필요한 라이브러리와 다양한 개발 및 디버깅 도구를 제공한다. ROS는 로봇 응용 프로그램 개발을 위한 운영체제와 같은 로봇 플랫폼이다.

이 설명은 위키피디아에서 말하는 ROS의 정의이다

즉, Robot Operation System이라는 말과는 다르게, ROS는 운영체제가 아니라 로봇 개발을 위한 라이브러리(혹은 프레임워크)이다

그러면 이제 ROS는 로봇 프로그래밍을 위한 많은 라이브러리를 제공해주는 플렛폼이라는 것을 알게 되었다. 하지만 중요한것은 그게 아니다. 무엇보다 중요한 것은 구체적으로 ROS는 우리에게 어떤것을 제공해주고, 왜 ROS를 사용해야 할까?

2. ROS의 설계 사상

나는 개인적으로 다음과 같은 생각을 가지고 프로그래밍을 하는 편이다.

새로운 기술은 기존 기술이 가지고 있는 불편함을 해소하기 위해 만들어진다

어디까지나 개인적인 의견이지만, 적어도 내 철학대로라면 ROS를 사용해서 로봇 프로그래밍을 진행할 경우, ROS를 사용하지 않는 로봇 프로그래밍보다 훨씬 편한 부분이 존재한다는 것이다.

이를 정확하게 이해하기 위해서는 ROS 프로그래밍의 구조를 확인해야한다.

2.1 ROS의 구조

위의 사진은 ROS의 노드(Node)를 가시적으로 표현한 그림이다.

노드란, 컴퓨터 과학에서 말하는 네트워크 상에 존재하는 데이터 지점들을 의미한다.

구체적으로, TCP/IP 통신 등을 이용한 노드간의 통신... 같은 어려운 내용이 존재하는데, 이런 내용은 ROS Wiki를 비롯하여 많은 사람들이 설명해두었으니 자세한 내용이 알고싶다면 이쪽을 참고하자.

내가 강조하고 싶은 내용은, ROS는 노드(Node)라고 하는 작은 프로그램의 집합이며, 각각의 노드끼리 서로 Message를 주고 받고 할 수 있다는 점이다.

2.2 ROS를 이용한 프로그래밍

조금 구체적인 예시를 들어주면, 자율주행 프로그램은 보통 아래와 같은 로직으로 운영이 된다.

① 여러개의 센서로부터 데이터를 수신받는다
② 받은 데이터를 가공해서 주변 환경과 자차상태을 인지한다
③ 주변 환경과 자차상태로부터 어떤 행동을 취해야 할지 판단한다
④ 판단한 내용을 실행(주행)한다

그렇다면 위와 같은 내용을 ROS 없이 제로빌드를 한다면 아마도 다음과 같은 식으로 구성되지 않을까 싶다.


def listenSensor(port):
	# Code for listening sensor
	return sensorData
    
def hanleSensorData(sensorData):
	# Code for handle sensor data
	return envData
    
def makeDrivingAlgorithm(carState, envData):
	# Code for determine action
    return controlCmd
    
def controlCar(controlCmd):
	# Code for control car
	return carState
    

if __name__ == "__main__":
	th = thread.Threading(target=listenSensor)
	th.start()

	while True:
    	logic = makeDrivingAlgorithm(carState, envData)
        carState = controlCar(logic)

아마도, 하나의 프로그램 안에 ①부터 ④까지의 모든 행동 로직을 집어넣고, 센서 수신 등의 일부 부분은 멀티 쓰레드를 활용하여 반복하도록 프로그램을 작성해야 할 것이다.

하지만, 만약에 이런 방법으로 프로그램을 짠다면 많은 문제점들과 마주하게 될 것이 분명하다.

하나의 프로그램으로 구성된 이상, 예외 처리를 매우 신중하게 하지 않는다면 매우 사소한 예외로 프로그램 전체가 멈출 가능성도 있고, 기본적으로 이런 프로그램 방식은 싱글 코어를 이용한 연산을 하기 때문에 스케쥴링에도 문제가 발생한다.

또한, 로직들이 서로 의존적으로 작성되어있기 때문에, 하나의 파트를 수정하다가 다른 부분이 연쇄적으로 문제를 만들어 낼 수 있다.

물론 이 모든 문제점을 염두해서 프로그램을 작성하는 것은 충분히 가능하다. 하지만 뭐라고 했는가?

새로운 기술은 기존 기술이 가지고 있는 불편함을 해소하기 위해 만들어진다

그렇다. 불편하다.

따라서 ROS를 사용한다면 위에 언급한 다양한 문제점을 간편하게 해결할 수 있다.

위와 같은 식으로 프로그램을 작성한다면, 하나의 노드가 멈춰도 전체적인 프로그램은 작동하며(물론 멈춘 노드에서는 데이터가 더이상 나오지 않을 것이니, 처리는 해줘야 한다), ROS가 자체적으로 프로그램 스케쥴링을 진행해주니, 자원 관리 측면에서 매우 편리해진다. 또한, 프로그램을 수정할 필요가 생겼을 때는, 각각의 노드를 수정하면 그만이고, 만약 노드 하나를 수정하다가 문제가 생겼다 하더라고, 메세지를 주고 보내는 부분만 잘 처리 한다면 정상적으로 작동할 것이다.

그리고, 다른 노드에서 발행하는 정보가 추가적으로 필요해질 경우, 해당 노드에서 발행(Publish)하는 메세지를 수신(Subscribe)하는 부분만 추가하면 끝나기 때문에, 확장성 면에서도 매우 우수해진다.

결론적으로, ROS를 이용한 프로그래밍을 진행할 경우, 그렇지 않은 경우에 비하여 프로그램 안정성, 스케쥴링, 확장성 등 많은 분야에서 훨씬 편해지는 것이다.

3. ROS가 제공하는 도구(tool)

또한, ROS는 로봇 프로그래밍에 있어서 많은 도구들을 제공해준다. 그 중에서도 가장 많이 사용하게 될 도구들은 바로 시각화 도구이다.


강력한 시각화 도구 RVIZ

RVIZ를 이용한 시각화


ROS 프로그래밍에서 가장 많이 사용하게 될 시각화 도구는 바로 RVIZ이다. RVIZ는 ROS에서 노드들이 발행하는 메세지를 별도의 작업 없이 바로 시각화 할 수 있는 매우 강력한 도구이다.

한번 실제 코드를 보면 이해하기 훨씬 쉬울 것이다.


예를 들어, 차량의 현재 위치에 대한 메세지를 발행한다고 해보자.
ROS에서는 이에 대한 메세지 타입으로 nav_msg.msg.Odometry 라는 클래스를 제공해준다.

#!/usr/bin/env python


import rospy
from nav_msgs.msg import Odometry
import math
from tf.transformations import quaternion_from_euler


if __name__ == '__main__':
    rospy.init_node("odometry")  # define node name

    publisher = rospy.Publisher("odom", Odometry, queue_size=5)
    # publisher name: odom, msg type: Odometry

    r = rospy.Rate(10)  # node speed : 10hz
    while not rospy.is_shutdown():

        msg = Odometry()    # define msg
        msg.header.frame_id = "odom"
        msg.header.stamp = rospy.Time.now()

        msg.child_frame_id = "base_link"

        msg.pose.pose.position.x = 4
        msg.pose.pose.position.y = 3
        msg.pose.pose.position.z = 0

        quat = quaternion_from_euler(0, 0, math.radians(30))

        msg.pose.pose.orientation.x = quat[0]
        msg.pose.pose.orientation.y = quat[1]
        msg.pose.pose.orientation.z = quat[2]
        msg.pose.pose.orientation.w = quat[3]

        publisher.publish(msg)  # publish msg

        r.sleep()

이번에는 실제로 동작하는 코드로, 10hz의 주기로, (x, y, z) = (4, 3, 0), 그리고 z축 방향(yaw)으로 30'만큼 회전해 있는 Odometry 클래스의 메세지를 발행하는 매우 단순한 코드이다.

이 코드를 실행한 상태로 RVIZ를 실행하면 아래와 같이 보인다.

놀랍게도, 파이썬 코드 그 어디에도 시각화 관련 코드는 존재하지 않지만, RVIZ가 알아서 메세지를 수신받아서 시각화 해주었다! (빨, 초, 파 순으로 x, y, z축이다)

그렇다면 이번에는 시간이 지남에 따라 점점 앞으로 전진하는 코드로 바꾸어보자.

#!/usr/bin/env python


import rospy
from nav_msgs.msg import Odometry
import math
from tf.transformations import quaternion_from_euler


if __name__ == '__main__':
    rospy.init_node("odometry")  # define node name

    publisher = rospy.Publisher("odom", Odometry, queue_size=5)
    # publisher name: odom, msg type: Odometry

    x_position = 0.0

    r = rospy.Rate(1)  # node speed : 1hz
    while not rospy.is_shutdown():

        msg = Odometry()    # define msg
        msg.header.frame_id = "odom"
        msg.header.stamp = rospy.Time.now()

        msg.child_frame_id = "base_link"

        msg.pose.pose.position.x = x_position
        msg.pose.pose.position.y = 0
        msg.pose.pose.position.z = 0

        quat = quaternion_from_euler(0, 0, math.radians(0))

        msg.pose.pose.orientation.x = quat[0]
        msg.pose.pose.orientation.y = quat[1]
        msg.pose.pose.orientation.z = quat[2]
        msg.pose.pose.orientation.w = quat[3]

        x_position += 0.2

        publisher.publish(msg)  # publish msg

        r.sleep()

위 코드는 아까 전의 코드에서 약간 수정하여, 1hz 주기로 작동하며, 1초마다 x로 0.2씩 이동하는 Odometry 메세지를 발행한다.

GIF로 바꾸면서 화질이 나빠지긴 했지만... 빨간 화살표 모양의 Odometry가 앞으로 전진하는 것을 확인할 수 있다.

중요한 것은, 이런식으로 ROS가 제공해주는 메세지들은 전부 RVIZ 상에서 별도의 과정 없이 직접 시각화가 가능하다는 점이다!

4. 결론

ROS는 로봇 프로그래밍을 위한 라이브러리로, 사용할 경우 그렇지 않을 때에 비하여 많은 장점을 가진다. 또한, 시각화 도구를 비롯하여 많은 개발상 편의 도구를 제공해준다.

ROS 설계의 철학을 이해하고, 이를 잘 활용한다면, 앞으로 로봇 프로그래밍에 있어서 마주할 다양한 문제들을 ROS를 이용하여 쉽게 해결할 수 있을 것이다.

26개의 댓글

comment-user-thumbnail
2023년 8월 8일

Your post gives me a lot of information. I also can learn new things. I appreciate your sharing. Have you joined trap the cat? It is so fun.

답글 달기
comment-user-thumbnail
2023년 8월 25일

The goal of the video game dumb ways to die is to survive as long as you can while striving to overcome progressively difficult obstacles. Throughout the course of this game, you will have the opportunity to test your skills in 82 different types of mini-games.

답글 달기
comment-user-thumbnail
2024년 2월 2일

Walgreenslistens has two goals in mind: First off, Walgreens finds that the survey is a really useful tool for monitoring and raising customer satisfaction levels. They can find areas for change or improvement to better serve customers by gathering data on reactions, thoughts, and feedback from customers. Second, consumers gain by participating in the survey because it gives them an opportunity to voice their opinions about the goods and services that https://walgreensreceiptsurvey.site/ Pharmacy provides. They now have a direct channel to communicate their opinions to management, which may influence next product releases and customer care campaigns.

답글 달기
comment-user-thumbnail
2024년 2월 2일

Walgreenslistens has two goals in mind: First off, Walgreens finds that the survey is a really useful tool for monitoring and raising customer satisfaction levels. They can find areas for change or improvement to better serve customers by gathering data on reactions, thoughts, and feedback from customers. Second, consumers gain by participating in the survey because it gives them an opportunity to voice their opinions about the goods and services that https://walgreensreceiptsurvey.site/ Pharmacy provides. They now have a direct channel to communicate their opinions to management, which may influence next product releases and customer care campaigns.

답글 달기
comment-user-thumbnail
2024년 2월 5일

It's critical to consider client input in order to guarantee consumer pleasure. Such surveys are carried out by the majority of large, prosperous businesses to learn about the attitudes of their clientele. Actually, the key to these polls' success is just this. Additionally, Lowe's runs a monthly poll on https://loves-survey.com/ which aids in the company's ability to increase customer satisfaction through practical changes. This survey aims to track performance exclusively on the basis of customer satisfaction.

답글 달기
comment-user-thumbnail
2024년 2월 6일

First, go to tellthebell.com Taco Bell's official website. To make an account, click the "Join Now" option on the homepage and input your name, email address, and password. Additionally, they will need to know some information about you, such as your gender and age group, so they can customize their offers. After finishing, click "Submit" to finish the registration process! https://tellthebelllwin.com/

답글 달기
comment-user-thumbnail
2024년 2월 7일

To take part in the Home Depot Customer Survey, please visit https://homdpotcomsurveys.store/. You may enter to win fantastic prizes like cash, gift cards, and gifts or discounts by completing the online survey. We are thus accessible to provide you with any information you want on the Home Depot Customer Survey. Please read on for further details and information about the survey.

답글 달기
comment-user-thumbnail
2024년 2월 8일

Features & Advantages of MyLowesLife: At Lowe's, the well-known home improvement retailer, employees benefit greatly from an inventive and all-encompassing employee portal that is essential to improving their work experience. https://mylows-life.org/

답글 달기
comment-user-thumbnail
2024년 2월 8일

If you need a fresh representation of your musical preferences, Receiptify is prepared to convert your rhythmic explorations into an authentic image. Its capacity to convert personal playlists into a distinctive, receipt-like image is what is attracting more and more users: it offers a peculiar way for users to display the songs they have chosen. https://receiptify.live/

답글 달기
comment-user-thumbnail
2024년 2월 9일

The TTU provides the student with this electronic identity. This includes the student's password and login. To access the campus WiFi, TechMail, class registration link, and any other information on the Raiderlink platform, students must have an active eRaider account. Students are given this special code by the university as soon as they are admitted. Since you will be using these credentials each time you enter into the Raiderlink site, you should never divulge your eRaider username and password to third parties. https://raiderlinkttu.co/

답글 달기
comment-user-thumbnail
2024년 2월 10일

There are several prerequisites that participants must fulfil in order to take part in the Home Depot survey. First and foremost, participants have to be at least eighteen. Second, they have to be citizens of either Canada or the United States. Thirdly, individuals need to present a legitimate receipt from a recent Home Depot transaction. Finally, a computer or mobile device with an internet connection is required for participation.
https://homedeptcomsurvey.top/

답글 달기
comment-user-thumbnail
2024년 2월 14일

Suppose you filled out an online application for a new LL Bean MasterCard and received your card in the mail or, in the case of digital cards, by email.
https://activatellbeenmastarcard.shop/

답글 달기
comment-user-thumbnail
2024년 2월 16일

This is the response. Visit https://homdpotcomsurveys.info/ to read more about this article on the Home Depot Survey and enter to win $5000 in Home Depot gift cards. To enter the contest, read the Home Depot Customer Survey regulations and follow the instructions. This post will provide you all the details you need to know about the guidelines and prerequisites for the Home Depot Customer Survey, as well as a step-by-step tutorial on how to do it.

답글 달기
comment-user-thumbnail
2024년 2월 16일

Dollar General is pleased to invite its newly acquired retail customers to participate in the $100 Customer Card Survey, which may be accessed at https://dgcustomerfirst.shop/ They may share their thoughts about Dollar General products, store conditions, and the quality of customer service they had in addition to being given the chance to win $100.

답글 달기
comment-user-thumbnail
2024년 2월 24일

MyKFCExperience's primary goal is to compile data regarding the degree of satisfaction that KFC patrons who have utilized their services at one of their locations have with them. In essence, it's a survey on consumer happiness. To assist them in determining the degree of satisfaction among their consumers, they have developed an extensive customer satisfaction survey. Customers can share their honest thoughts about KFC via the https://mykfcxperiencewingiftcard.com/ survey. Representatives of the business will take the comments into account and modify their services to give clients top-notch support.

답글 달기
comment-user-thumbnail
2024년 2월 28일

Loyal L.L.Bean consumers are drawn to the allure of the L.L.Bean Mastercard because of its financing perks, special discounts, and personalised incentives. Its effectiveness, nevertheless, depends on matching incentives to personal spending patterns. https://activatellbeeanmestercard.org/

답글 달기
comment-user-thumbnail
2024년 2월 29일

Have you lately made use of Value Village's customer service? How did your experience turn out? Value Village is a developing store selling used clothing and other goods. You know as a business owner that surveys are a great way to get consumer data and promote your brand. It's an excellent resource that gives you crucial guidance on what to do and what not to do. Consumer feedback makes it easier to come up with new ideas for improving the business. The Value Village survey was developed by the company to improve customer satisfaction. Fill out the form to be entered to win a $2 off voucher. https://valuevillagelistensus.one/

답글 달기
comment-user-thumbnail
2024년 3월 1일

For the benefit of the customers, the Lowes store has designated the Lowe's customer satisfaction survey, which may be accessed online at https://lowscomsurvey.click/. They may share their thoughts, suggestions, and any problems they had while visiting here. Consumers can submit concerns they have about goods, cleansers, situations, representative conduct, and other topics by filling out the current Lowe's survey. They may enter to win a $500 prize after finishing the survey.

답글 달기
comment-user-thumbnail
2024년 3월 4일

TalkToWendys and WendysWantsToKnow are two companies that provide the consumer satisfaction surveys. Wendy's solicits customer feedback and makes service changes through a survey program called WendysWantsToKnow, which is often referred to as TalkToWendys. Customers may visit https://talktowendyswinfreesandwich.info/ or talktowendys.com to take part in the Wendy's survey.

답글 달기
comment-user-thumbnail
2024년 3월 12일

Companies frequently use surveys as a tool to find out what their clients think and feel about them. Companies greatly appreciate client input because it helps them improve the customer experience. The majority of businesses also provide incentives for customers who take the time to complete the survey in order to entice them to do so. The https://talktostopandshopcom.shop/ Survey is one such customer survey. Stop & Shop is a supermarket that sells everyday essentials and groceries. Everything you need for your kitchen and bathroom is right here. In the northeastern region of the United States, Stop & Shop has more than 420 locations.

답글 달기
comment-user-thumbnail
2024년 3월 12일

Miss Dress For Less is one of the most well-known stores in the United States. You may use RossListens to redeem prizes and make purchases here for less money. It goes without saying that you will have some opinions on your visit after leaving the business. RossListens are used by the company since they are ready for your feedback. I'll go over the basics of the survey in this review and show you how to fill it out after shopping at any of the many US shops. Learn more about the benefits of making your purchase at https://rosslistenscom.store/ and then filling out the online survey there by reading on.

답글 달기
comment-user-thumbnail
2024년 3월 13일

MyLowesLife is the official website accessible to both current and former Lowe's workers. Registered users may immediately acquire access to the portal and utilize all of the services provided by the business by only viewing this advantage. All employees and representatives of Lowe have access to crucial data on their income, perks, number of hours worked, and other rewards. The Lowe's Company created the MyLowesLife.com Employee Login page as a way to show their gratitude for their workers and make their workplaces more enjoyable. https://myloweslife.store/

답글 달기
comment-user-thumbnail
2024년 3월 14일

Customers of the well-known supermarket chain Lowe's are being invited to participate in their customer satisfaction survey. In less than five minutes, this brief survey available at https://lows-comsurvey.org/ will question you about your most recent shopping experiences. By participating, you may voice your opinion and be eligible to win a $500 monthly reward. Discuss your ideas with Lowe's and you could just win big!

답글 달기
comment-user-thumbnail
2024년 3월 15일

You can get the Walgreens Survey Rewards once you finish the survey and provide the necessary information. The winners will be declared at https://wallgreenslistens.store/ the company's official website. Should you win, the phone number or email address you provided on the survey will be used to notify you.

답글 달기
comment-user-thumbnail
2024년 3월 17일

It takes no more than five minutes to complete the Value Village Customer Satisfaction Survey, which is short and easy to complete. As such, you will need to be informed of any survey restrictions and criteria in advance in addition to the survey instructions. In essence, the Value Village store offers second-hand shopping to its patrons who are budget conscious, value saving money over wasting it on clothing, and want to receive rewards before switching to the Value Village customer survey. https://valuevillagelistens.us/

답글 달기
comment-user-thumbnail
2024년 3월 19일

The bill you received was related to laboratory tests that your doctor requested from Quest Diagnostics. This charge is exclusive to the expenses related to laboratory testing; it is not related to any invoices you may have received from your physician or paid at the physician's office. Even though you may not have physically visited a Quest Diagnostics location, your doctor may nonetheless have sent your samples to a Quest Diagnostics laboratory for analysis. https://mydocbillcom.quest/

답글 달기