ROS系统开发中使用Qt Creator 作为IDE
管理catkin_make项目
使用Qt Creator 管理catkin_make项目,可以更加系统地开发代码包。
1、安装并打开Qt Creator
本文中使用的是Qt Creator 3.5.1,基于Qt 5.5.1和 GCC 5.2.1。
注意,要在终端中打开Qt Creator,不然会报错如下
:
//直接双击打开Qt Creator
find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.
在终端中打开Qt Creator ,可以解决以上问题。
//在终端打开Qt Creator
slam-nuc@slam-nuc:~$ qtcreator
2、导入已有的catkin_make项目
- 将符号链接的CMakeLists.txt 文件替换为实体文件
slam-nuc@slam-nuc:~$ cd ~/catkin_ws_testqt/src | sed -i '' CMakeLists.txt
- 使用 Qt Creator中的 Open Project命令 ,打开catkin工作区的最高级CMakeLists.txt 文件。
- 设置CMake构建路径为
~/catkin_ws_testqt/build
- 设置执行CMake的相关参数为
-DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel
点击执行CMake,如果按之前的操作做完的话,这一步是不会出错的,直接通过。
6. 此时已经将整个catkin_make项目加入到Qt Creator中,可以方便的管理项目。
注意,如果没有看到项目,需要在视图中选择项目即可。
3、使用root身份进行编译和调试
- 使用su命令,获取root权限,进行编译通过。
slam-nuc@slam-nuc:~/catkin_ws_testqt$ su root
密码:
root@slam-nuc:/home/slam-nuc/catkin_ws_testqt# qtcreator
- 赋予普通用户root权限
添加用户,首先用adduser命令添加一个普通用户,命令如下:
slam-nuc@slam-nuc:~/catkin_ws_testqt$ sudo adduser haorui //添加一个名为claire的用户
slam-nuc@slam-nuc:~/catkin_ws_testqt$ sudo passwd haorui //change the password
changing password for user haorui
New unix password : //input new password
Retype new unix password: //input the new password again
password:all authentication tokens updated successfully.
赋予root 权限
slam-nuc@slam-nuc:~/catkin_ws_testqt$ sudo gedit /etc/sudoers
//找到%wheel 一行,把前面的注释(#)去掉
##Allow people in group wheel to run all commands
%wheel ALL=(ALL) ALL
//然后修改用户,使其属于root组(wheel),命令如下:
root ALL=(ALL) ALL
haorui ALL=(ALL) ALL
slam-nuc@slam-nuc:~/catkin_ws_testqt$ sudo usermod -g root haorui
修改完毕后,现在可以用haorui账号登陆,然后用sudo su haorui ,即可获得root权限进行操作。