2017년 3월 8일 수요일

#RobotOperatingSystem_ANDROIDwithROS_Kinetic



개발환경
(1) Ubuntu 16.04 LTS (Xenial Xerus)
! 참조로,Indigo는 Ubuntu 16에서 돌아가지 않는다.

(2) Ros Kinetic
  One line Install :
wget https://raw.githubusercontent.com/oroca/oroca-ros-pkg/kinetic/ros_install.sh && chmod 755 ./ros_install.sh && bash ./ros_install.sh catkin_ws kinetic
[출처] ROS Kinetic 1줄 설치! (오픈소스 소프트웨어 & 하드웨어: 로봇 기술 공유 카페 (오로카)) |작성자 표윤석

cf) 설치가 제대로 되지 않을 시 추가참조 :
http://hrepository.blogspot.kr/2017/01/robotoperatingsystem00.html
 
(3)Android Studio

http://hrepository.blogspot.kr/2017/01/ubuntu-androidstudio-tutoiral.html
 : 다음 페이지를 참조해서 설치하도록하자.
참고로,
- select Configure->SDK Manager option make sure you have installed Android SDK Build Tools 25.0.2, Android APIs 10 (gingerbread), 13 (honeycomb), 15 (ice cream), 18 (jellybean).(위와 같은 것들의 설치가 필요하다.)
- Some settings you might like to configure: Version Control->Github
- make sure you have the latest. (가장 최근 버전으로 update하시오.)
path에 다음을 추가하시오.
(이것은 Android Studiofmf /opt/android-studio나 /opt/android-sdk가 아닌곳에서도 작동할 수 있게 수정해야한다.)
$ echo export PATH=\${PATH}:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/android-studio/bin >> ~/.bashrc
$ echo export ANDROID_HOME=/opt/android-sdk >> ~/.bashrc
 
 
Error
"Inotify Watches Limit" https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit
 이 페이지에서 언급한 에러가 난다면,
  페이지에서 언급 된 것처럼 
(1) > vim /etc/sysctl.conf
파일 아래에 다음을 추가해준다.
> fs.inotify.max_user_watches = 524288
 
 or
 
 (2) 새로운 .conf file을 /etc/sysctl.d/ directory 아래에 추가해준다. 예를 들면 idea.conf같이 생성해서
파일에 다음을 작성해준다.
> fs.inotify.max_user_watches = 524288
 
 본인은 (1)방법으로 실행하였다.
그리고 두 방법 중 한 방법을 적용한 뒤 

> sudo sysctl -p --system
#바뀐 설정을 적용하기 위해 명령을 해준다. 
 
자, 이제 IDE를 재시작해보자. 
 

<START>
 먼저,Android와 ROS의 연결을 확인하기 위해 ROS Wiki의 예제를 따라해보자.
Android를 작성하기 위해서 Java가 필요하니, rosjava를 먼저 설치하기를 말하고 있으나, 본인은 홈페이지를 따라 같이 설치하는 방향으로 간다.

(1) PreRequisites
sudo apt-get install ros-kinetic-rosjava-build-tools
 
(2) Core Sources
 > mkdir -p ~/android_core
> wstool init -j4 ~/android_core/src https://raw.github.com/rosjava/rosjava/kinetic/android_core.rosinstall
> source /opt/ros/kinetic/setup.bash
> # You only need to do the next step if you opted for a source installation of rosjava:
> source ~/rosjava/devel/setup.bash //rosjava를 미리 설치한 사람만 실행할 것.
> cd ~/android_core
> catkin_make // ***이쯤에서 실행이 안 될 경우, 
***~/android_core/src/android_extras폴더를 삭제 혹은 ~/으로 이동 시킨 후 다시 catkin_make를 실행해보자.

(3)Your Own Sources
workspace를 두개로 나눈다. 하나는 완전히 자바 workspace 그리고 다른 하나는 java workspace에서 네 작업을 늦추지 않기 위한 android workspace.
(자바에서 하는 building/testing는 ros연결이 안드로이드로 연결하는 것보다 훨씬 쉽다.)

> sudo apt-get install ros-kinetic-rosjava-build-tools ros-kinetic-genjava
 
 > mkdir -p ~/myjava
 
 > wstool init -j4 ~/myjava/src my_java_sources.rosinstall
 > wstool init ~/myjava/src // 아직 rosinstalls 하지 않았다면
 
 > mkdir -p ~/myandroid
 
 > wstool init -j4 ~/myandroid/src my_android_sources.rosinstall
 > wstool init ~/myandroid/src // 아직 rosinstalls 하지 않았다면
 
 
 > source /opt/ros/kinetic/setup.bash
 
 > cd ~/myjava; catkin_make
 
 > source ~/myjava/devel/setup.bash
 
 > cd ~/myandroid; catkin_make


(4) Testing

pc :
In a first shell

> source /opt/ros/kinetic/setup.bash
# Set ROS_IP with your pc's ip
> export ROS_IP=192.168.1.101 //본인의 ip로 바꿀 것!
> roscore
 
 
아랫쪽을 보면 ROS_MASTER_URI=http://192.168.25.62:11311/로 바뀐다는 것을 알 수 있다.
만약 이것이 export해도 바뀌지 않는다면, .bashrc에 강제로 선언이 되어 있는 경우도 있으니
> vi .bashrc
에서 ROS_MASTER_URI설정을 없애던가 강제적으로 적어 넣어준다.
export ROS_MASTER_URI=http://192.168.25.62:11311
export ROS_IP=192.168.25.62 //참고로, ROS_HOSTNAME이나 ROS_IP 둘 중 하나만 써주면 된다.
 
In a second shell
 
> sudo apt-get install ros-kinetic-image-view ros-kinetic-rqt-image-view ros-kinetic-image-transport-plugins
> source /opt/ros/kinetic/setup.bash
# Set ROS_IP with your pc's ip
> export ROS_IP=192.168.1.101 //본인의 ip로 바꿀 것! 만약, 위에서 .bashrc에 직접 적었다면 다시 설정 해 줄 필요가 없다.
 > rqt_image_view
# OR
> rosrun image_view image_view image:=/camera/image _image_transport:=compressed

자세한 ROS_IP에 대한 정보는 ?
http://wiki.ros.org/ROS/NetworkSetup#Setting_a_name_explicitly

Android

> source ~/android_core/devel/setup.bash
> /opt/android-studio/bin/studio.sh // Android 실행 studio.sh
 
- File >  New > Import Project
 ~/android_core/src/android_core를 import한다.
 
- phone을 pc에 연결시켜서 실행하도록 한다.
 
본인이 중간에 일어난 오류 사항에 대해서만 작성하도록 하겠다. 중간에 다른 오류 사항이 일어날 수 있지만,
차근차근 오류를 검색하여 수정하도록 하자.
 
실행 시 일어나는 오류,
  
!!! error while loading shared libraries: libopencv_core.so.2.4: 
cannot open shared object file: No such file or directory
 
 File > Settings > Build,Execution,Deployment > InstantRun > check Boxes 모두 해제!
 
 Build > Clean Project
 Build > Rebuild Project 하면 문제가 해결된다.


기본 화면
본인이 ros core를 연결할 때 사용한 ip를 적어준다.

 advanced options를 wifi가 공유되는 상황에서 설정
New Private Master -> Hz화면이 뜬다.

 advanced options를 wifi가 공유되지 않는 상황에서 설정
New Private Master -> 오류 발생 -> 강제 종료


 <Ros 화면>


 

이렇게 돌아가긴 하는데 정말 이게 프로그램이 작동한 것일까? 하는 의문이 드니,
ros_graph를 실행시켜보자.

In a third shell
>rqt_graph
 정상적으로 작동한다는 것을 알 수 있다. 왜냐하면, 모바일 상의 앱을 종료하였을 때 roscore가 켜져 있음에도 어떤 토픽도 존재하지 않는 화면이 나타나기 때문에 roscore에서 정상적으로 연결이 되었음을 확인 할 수 있었다.

결론 : 솔직히 이 프로그램이 정확히 무엇을 위한 프로그램인지 아직 정확히 파악하진 못했음.
하지만, ros 자체가 android에 올라가서 돌아간다는 점. 그리고 ros와 android간의 연결이 ip로 연결한다는 점을 짚고 넘어갈 수 있음.

댓글 없음:

댓글 쓰기