๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

19. [ROS RC์นด] ํ”„๋กœ์ ํŠธ Setup, DonkeyCar ๋‘˜๋Ÿฌ๋ณด๊ธฐ

๐Ÿ•Œ

19. [ROS RC์นด] ํ”„๋กœ์ ํŠธ Setup, DonkeyCar ๋‘˜๋Ÿฌ๋ณด๊ธฐ

๋ณธ๊ฒฉ์ ์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ด์™€ ๋”๋ถˆ์–ด, ๊ฐ™์€ ํ•˜๋“œ์›จ์–ด๋กœ ์ง„ํ–‰ ๊ฐ€๋Šฅํ•œ ๋˜ ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์ธ Donkey Car ์„ค์ •๋„ ์•Œ์•„๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

  • ํ•„์š” ์†Œ์Šค์ฝ”๋“œ clone
$ cd ~/catkin_ws/src
$ git clone https://github.com/Road-Balance/donkey_ros.git

$ cd ~/catkin_ws
$ cma
Road-Balance/donkey_ros
donkey car with ROS!! Contribute to Road-Balance/donkey_ros development by creating an account on GitHub.
https://github.com/Road-Balance/donkey_ros

cma ์ค‘ ๊ด€๋ จ ์ข…์†์„ฑ ๋ฌธ์ œ๋กœ ์™„๋ฃŒ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ ๋‹ค์Œ์˜ ์ปค๋ฉ˜๋“œ๋ฅผ ํ†ตํ•ด ros ์ข…์†์„ฑ๋“ค์„ ์†์‰ฝ๊ฒŒ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ rosdep install --from-paths src --ignore-src -r -y

[Option] DonkeyCar Setup


๐Ÿ’ก
ROS์—๋งŒ ์ง‘์ค‘ํ•˜๊ธธ ์›ํ•˜์‹ ๋‹ค๋ฉด, ์Šคํ‚ตํ•œ ๋’ค์— ๋‚˜์ค‘์— ๋Œ์•„์˜ค์…”๋„ ์ข‹์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ๋”ฐ๋ผ์˜ค์‹œ๋ฉด, ๋ฉ‹์žˆ๋Š” ์—ฌ๋Ÿฌ๋ถ„๋งŒ์˜ RC์นด๊ฐ€ ์ƒ๊ธฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

ROS๋Š” ์•„๋‹ˆ์ง€๋งŒ, ์ด ๋™์ผํ•œ ํ•˜๋“œ์›จ์–ด๋กœ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋˜๋‹ค๋ฅธ ๋ฉ‹์žˆ๋Š” ๊ฐ•ํ™”ํ•™์Šต ํ”„๋กœ์ ํŠธ, Donkey Car ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด๋ด…๋‹ˆ๋‹ค.

ํŒŒ์ด์ฌ ๊ฐ€์ƒํ™˜๊ฒฝ

๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ž€? ํ•„์š”ํ•œ ์ด์œ ๋Š”?

  • project A
    • numpy=1.17.1
    • django
    • ...

  • project B
    • pymongo
    • beautifulSoup
    • ...
  • project C
    • numpy=1.18.5
    • matplotlib
    • ...

ํŒŒ์ด์ฌ์˜ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๋„๊ตฌ๋“ค

  • pipenv
  • pyenv
  • anaconda
  • virtualenv
  • venv

  • ๋ชจ๋“  ์„ค์น˜ ๊ณผ์ •์€ ํ•ด๋‹น ํŽ˜์ด์ง€์— ๊ธฐ๋ฐ˜ํ•ฉ๋‹ˆ๋‹ค.
Get Your Jetson Nano Working
Visit the official Nvidia Jetson Nano Getting Started Guide. Work through the Prepare for Setup, Writing Image to the microSD Card, and Setup and First Boot instructions, then return here. ssh into your vehicle. Use the the terminal for Ubuntu or Mac. Putty for windows.
http://docs.donkeycar.com/guide/robot_sbc/setup_jetson_nano/

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential python3 python3-dev python3-pip python3-pandas python3-h5py libhdf5-serial-dev hdf5-tools nano ntp

$ pip3 install virtualenv
$ python3 -m virtualenv -p python3 env --system-site-packages
$ python3 -m virtualenv -p python3 donkey_env 

$ echo "source env/bin/activate" >> ~/.bashrc
$ source ~/.bashrc
$ deactivate
$ source env/bin/activate

$ mkdir -p ~/donkey; cd ~/donkey

$ git clone https://github.com/autorope/donkeycar
$ cd donkeycar
$ git checkout master

$ pip install --upgrade setuptools
$ pip install --upgrade pip

$ pip install -e .[nano]

$ sudo apt-cache show nvidia-jetpack | grep Version

$ # For Jetpack 4.4,
$ pip install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 'tensorflow<2'

$ sudo apt-get install python-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev libfreetype6-dev

Create your car application


Create Donkeycar App. - Donkey Car
If you are not already, please ssh into your vehicle. Create a set of files to control your Donkey with this command: donkey createcar --path ~/mycar See also more information on createcar. Look at myconfig.py in your newly created directory, ~/mycar cd ~/mycar nano myconfig.py Each line has a comment mark.
http://docs.donkeycar.com/guide/create_application/
$ donkey createcar --path ~/donkey/mycar

________             ______                   _________              
___  __ \_______________  /___________  __    __  ____/_____ ________
__  / / /  __ \_  __ \_  //_/  _ \_  / / /    _  /    _  __ `/_  ___/
_  /_/ // /_/ /  / / /  ,<  /  __/  /_/ /     / /___  / /_/ /_  /    
/_____/ \____//_/ /_//_/|_| \___/_\__, /      \____/  \__,_/ /_/     
                                 /____/                              

using donkey v4.1.0 ...
Creating car folder: /home/swimming/donkeyROS/mycar
making dir  /home/swimming/donkeyROS/mycar
Creating data & model folders.
making dir  /home/swimming/donkeyROS/mycar/models
making dir  /home/swimming/donkeyROS/mycar/data
making dir  /home/swimming/donkeyROS/mycar/logs
Copying car application template: basic
Copying car config defaults. Adjust these before starting your car.
Copying train script. Adjust these before starting your car.
Copying calibrate script. Adjust these before starting your car.
Copying my car config overrides
Donkey setup complete.

Calibrate your Car


๊ธฐ๊ธฐ๋งˆ๋‹ค ์ „์ง„, ๋ฐฉํ–ฅ ์ „ํ™˜์„ ์œ„ํ•œ PWM pulse์˜ ๋Œ€์—ญํญ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฅผ ์œ„ํ•ด calibration์ด ํ•„์š”ํ•œ๋ฐ์š”, ์ด ๊ฐ’์€ ์ž˜ ์ ์–ด๋‘์—ˆ๋‹ค๊ฐ€ ROS ํ”„๋กœ์ ํŠธ์—๋„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿ‘

Calibrate steering and throttle. - Donkey Car
The point of calibrating your car is to make it drive consistently. You will need to ssh into your Pi to do the calibration. All of the car's settings are in the config.py and myconfig.py scripts generated when you ran the donkey createcar --path ~/mycar command.
http://docs.donkeycar.com/guide/calibrate/

PCA board. It should be 1 or 0.

$ cd ~/donkey/donkeycar
# servo
$ donkey calibrate --channel 1 --bus=1
# throttle
$ donkey calibrate --channel 0 --bus=1


________             ______                   _________              
___  __ \_______________  /___________  __    __  ____/_____ ________
__  / / /  __ \_  __ \_  //_/  _ \_  / / /    _  /    _  __ `/_  ___/
_  /_/ // /_/ /  / / /  ,<  /  __/  /_/ /     / /___  / /_/ /_  /    
/_____/ \____//_/ /_//_/|_| \___/_\__, /      \____/  \__,_/ /_/     
                                 /____/                              

using donkey v4.1.0 ...
init PCA9685 on channel 0 address 0x40 bus 1
Using PWM freq: 60

Enter a PWM setting to test ('q' for quit) (0-1500): 400
Enter a PWM setting to test ('q' for quit) (0-1500): 

  • ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ mycar/myconfig.py์— ์ ์–ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

  • ๋‹ค์Œ์œผ๋กœ ์นด๋ฉ”๋ผ ์„ธํŒ…์ž…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์นด๋ฉ”๋ผ์˜ ์ •๋ณด๋ฅผ ๋‹ค์‹œ ํ•œ ๋ฒˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
IMX219 ์ ฏ์Šจ๋‚˜๋…ธ 160๋„ ๊ด‘๊ฐ ์นด๋ฉ”๋ผ ๋ชจ๋“ˆ 8MP
๋ฐฐ์†ก๊ธˆ์•ก ๋กฏ๋ฐํƒ๋ฐฐ(๊ตฌ.ํ˜„๋Œ€ํƒ๋ฐฐ)(2,500์›)๊ตฌ๋งค๊ธˆ์•ก์ด 6๋งŒ์›์ด์ƒ ๊ตฌ๋งค์‹œ(๋ถ€๊ฐ€์„ธ๋ณ„๋„) ๋ฐฐ์†ก๋ฃŒ ๋ฌด๋ฃŒ ๋ฐฐ์†ก๋ฐฉ๋ฒ• 1. ๋กฏ๋ฐํƒ๋ฐฐ(๊ตฌ.ํ˜„๋Œ€ํƒ๋ฐฐ)(2,500์›) ๋ฐœ์†กํ›„ ํ‰๊ท  2,3์ผ๋‚ด ์ˆ˜๋ น ๊ฐ€๋Šฅํ•˜๋ฉฐ ํƒ๋ฐฐ์‚ฌ์˜ ์‚ฌ์ •์— ๋”ฐ๋ผ ๋‹ค์†Œ ์ง€์—ฐ(1~3์ผ) ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋กฏ๋ฐํƒ๋ฐฐ(๊ตฌ.ํ˜„๋Œ€ํƒ๋ฐฐ) ๋ฐฐ์†ก์กฐํšŒ:1588-2121 2. ํ€ต์„œ๋น„์Šค ํ€ต์„œ๋น„์Šค๋Š” ๊ตฌ๋งค์ž๋ถ€๋‹ด(์ฐฉ๋ถˆ)์ž…๋‹ˆ๋‹ค. ์„œ์šธ ์ „์ง€์—ญ๊ณผ ๊ฒฝ๊ธฐ ์ผ๋ถ€์ง€์—ญ์—์„œ ๊ฐ€๋Šฅํ•œ ์„œ๋น„์Šค ์ž…๋‹ˆ๋‹ค. (๊ณ ์–‘์‹œ, ์ผ์‚ฐ, ๊ตฐํฌ, ์•ˆ์–‘, ๊ณผ์ฒœ, ๊ด‘๋ช…์ผ๋ถ€, ์„ฑ๋‚จ, ๋ถ„๋‹น) ํ€ต์„œ๋น„์Šค๊ฐ€๋Šฅ์—ฌ๋ถ€๋Š” ์ฃผ๋ฌธ์„ ์ฃผ์‹ ํ›„ ์ „ํ™”์—ฐ๋ฝ์ฃผ์„ธ์š”.
https://www.devicemart.co.kr/goods/view?no=12538383

๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์นด๋ฉ”๋ผ์™€ ๋™์ผํ•œ IMX219 ์ด๋ฏธ์ง€ ์„ผ์„œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ์„ค์ •์„ ์œ„ํ•ด์„œ, ์œ„์™€ ๊ฐ™์ด ํ™”๋ฉด ํ”ฝ์…€, Flip ๋“ฑ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์•ž์„œ ์™œ Flip์ด 2๊ฐ€ ๋˜๋Š”์ง€ ์„ค๋ช…ํ–ˆ์ง€์š”??

Drive


์„ค์ •์„ ๋ชจ๋‘ ๋งˆ์ณค๋‹ค๋ฉด, ์ด์ œ Donkey Car๋ฅผ ์ฃผํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์€ ์ปค๋งจ๋“œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ , 8887 ํฌํŠธ๋กœ ๋“ค์–ด๊ฐ€๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์›น ์ปจํŠธ๋กค๋Ÿฌ ํ™”๋ฉด์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!!

cd ~/donkey/mycar
python manage.py drive

๐Ÿ’ก
๋ฆฌ๋ˆ…์Šค์—์„œ ์ž์‹ ์˜ ip๋ฅผ ์•Œ์•„๋‚ด๋Š” ๋ฐฉ๋ฒ•์€ hostname -I ์ž…๋‹ˆ๋‹ค.
๐Ÿ’ก
๋™ํ‚ค์นด ์ œ์–ด๋ฅผ ์œ„ํ•ด์„œ i, j, k, l์„ ์‚ฌ์šฉํ•˜์„ธ์š” ๐Ÿ™‚

์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋๋‚˜๊ณ  ๋‚œ ๋’ค, ๊ฐ•ํ™”ํ•™์Šต์„ ์‚ฌ์šฉํ•˜์—ฌ Donkey Car๋„ ๋„์ „ํ•ด๋ณด์„ธ์š”!! ๐Ÿš—๐Ÿš—