2691 views|1 replies

654

Posts

26

Resources
The OP
 

35 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (Realizing Hello World) [Copy link]

 

The best way to learn ROS is to use it. The ROS official website has a Chinese version of the tutorial . After installing ROS, write the first program "Hello world".

1 Create a workspace

Open a terminal window and enter the following command.

mkdir -p helloworld_ws/src
cd helloworld_ws
catkin_make

The command creates a workspace called "helloworld_ws" with a subdirectory called "src" and compiles it. The compile command can also be replaced by catkin build. Once you start using one, you will need to use it all the time. After the catkin build command is compiled, there will be an additional .catkin_tools hidden folder compared to the catkin_make command.

2. Create a function package

cd src
catkin_create_pkg helloworld roscpp rospy std_msgs

Enter the "src" file, set the package name to "helloworld", and add the "roscpp rospy std_msgs" dependency

3 Edit source files

cd helloworld/src
pluma helloworld_c.cpp

Enter the "src" file in the package, use the pluma editor to create and edit a file named "helloworld_c.cpp". Enter the following code in the file.

#include <ros/ros.h>
int main(int argc,char *argv[]){
  ROS_INFO("Hello world!");
  return 0;
}

The code includes the "ros.h" header file and then outputs "Hello world!" in the main function.

4 Edit the configuration file

Edit the "CMakeLists.txt" file in the "helloworld" package (helloworld_ws/src/helloword/src/CMakeLists.txt)

Modify line 136 or add the following code below it.

aux_source_directory(./src SRCS)
add_executable(${PROJECT_NAME}_node ${SRCS})

The code creates an executable file named "package name_node" from all the source files in the "/src" directory. The compiled executable file is in "helloworld_ws/devel/lib/hellowrold".

Modify line 149 or add the following code below it.

target_link_libraries(${PROJECT_NAME}_node
${catkin_LIBRARIES}
)

The code links the generated executable file with the catkin library file.

5 Start the kernel

Reopen a terminal and enter.

roscore

This command starts the ROS kernel. In this example, it doesn't matter if it is not started.

6 Compiled

Reopen a terminal and enter.

cd ~/helloworld_ws
catkin_make

Go into the "helloworld_ws" file and compile it.

7 Run

source ./devel/setup.bash
rosrun helloworld helloworld_node

"source devel/setup.bash" makes the environment variable script in the devel directory take effect, otherwise the helloworld package will not be found.

"rosrun helloworld helloworld_node" runs the helloworld_node executable file under the helloworld package.

Finally, you can see the successful output "Hello world!"

question

It is very troublesome to run ROS using operating instructions throughout the process. Is there a good IDE?

image-20220510000237-1.png (93.17 KB, downloads: 0)

image-20220510000237-1.png
This post is from Innovation Lab

Latest reply

The best way to learn ROS is to use it. The ROS official website has a Chinese version of the tutorial . After installing ROS, write the first program "Hello world". Everything starts with hello world!   Details Published on 2022-11-5 07:44
Personal signatureQQ:252669569
 
 

6841

Posts

11

Resources
2
 

The best way to learn ROS is to use it. The ROS official website has a Chinese version of the tutorial . After installing ROS, write the first program "Hello world".

Everything starts with hello world!

This post is from Innovation Lab
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list