반응형

이번에 Pixhawk 카피본을 제작해 보았다. 오픈소스 하드웨어 프로젝트라서 회로도가 모두 공개되어 있으므로 복사하는것 자체는 어렵지 않지만 

회로도대로 PCB를 설계하고 만드는 작업은 아주 어려운 과정이었다.

몇번의 시행착오 끝에 설계를 완성할 수 있었다. 보드 크기는 얼마 되지 않지만 작은 사이즈에 실장되는 부품들이 많아서 공간에 구겨 넣는 작업이 만만치 않으므로 천상 수삽은 어렵고 SMT를 통해 제작해야만 한다. 

저항이나 캡들은 모두 1005 사이즈로 설계하였다.


실제로 완성된 보드의 모습.


하지만 보드가 완성되었다고 해서 바로 연결하면 Pixhawk로 동작하지 않는다. PC에서 USB에 연결했을 때 Pixhawk 모듈로 인식하는 것은 기본적으로

USB연결을 가능하게 해주는 Bootloader가 올라가 있기 때문이다. 

만약 부트로더가 없다면 해당 타겟의 개발자용으로 나온 값비싼 JTAG같은 프로그래머를 사용해야 한다. 

부트로더는 쉽게 이야기하자면 정해진 규칙에 따라 사용자 프로그램을 타겟 보드에 올릴 수 있는 연결 통로라고 할 수 있다.

픽스호크는 크게 2개의 CPU 혹은 마이크로 컨트롤러로 구성되는데 PX4IO와  PX4FMU이고 각각 STM32F1 과 STM32F4 버전의 컨트롤러가 장착된다.

FMU에 해당하는 칩이 보드에 가장 크게 장착된 컨트롤러로서 USB가 연결되고 자세제어 등 상위 제어에 사용되는 칩이다.

STM은 친절하게도 보드에 부트로더를 쉽게 구울 수 있도록 하는 여러가지 기능을 제공하는데 DFU가 바로 그것이다.

DFU란 Device Firmware Upgrade를 의미하는데 칩 자체에 별도의 부트로더 영역이 있어서 시작할때 부트로더 영역으로 진입하게 되면 사용자 프로그램을 

업로드할 수 있는 연결 인터페이스가 제공된다. 

통신 프로토콜을 따라 별도로 업로드하는 프로그램을 제작할 수 있지만 STM에서는 아래 링크에서 해당 프로그램을 제공하고 있다.

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/stsw-stm32080.html


간단한 가입절차를 통해 프로그램을 다운로드할 수 있다.

설치하고 파일을 업로드 해보자.


먼저 다음 파일이 필요하다.

px4fmuv2_bl.bin 이라는 파일인데 부트로더 이미지이다. 아래 링크에서 다운로드 한다.

https://github.com/ArduPilot/ardupilot/tree/master/mk/PX4/bootloader


bin파일을 dfu 파일로 변환해야 한다.

시작메뉴에서 STM... 아래에 Dfu file manager를 연다.


DFU파일을 만들 것이므로 첫번째 항목을 선택하고 OK를 클릭한다.


설정 화면에서 아래와 같이 설정한다.


  • Vendor ID: 0x 0483
  • Product ID: 0x df11
  • Version ID: 0x 2100


Multi BIN... 항목을 선택하여 변환할 파일을 추가한다.

File에는 앞서 다운로드받은 px4fmuv2_bl.bin 파일을 선택한다.


Address 는 0x08000000 으로 설정하고 Add to list>> 를 눌러 파일을 등록한다. OK 누르고 Generate.. 버튼을 누르면 파일 변환이 성공이다.



다음은 부트로더로 진입하는 방법이다.

아래 그림과 같이 FMU의 Boot0 Pin을 핀셋으로 High와 연결한 상태에서 PC의 USB선을 연결한다.


PC에서 USB인식이 끝나면 아래와 같이 장치관리자에 DFU장치로 인식이 될것이다.

이제 앞에서 만든 부트로더를 타겟에 올린다.

시작 -> STM... -> DfuseDemo를 선택하여 실행한다.


아래 그림과 같은 화면이 뜬다.



화면 하단의 Choose... 버튼을 눌러 아까 만든 .dfu파일을 선택한다.

파일이 정상적이라면 Load Success가 나타나고 아까 설정한 VendorID와  ProductID가 뜬다.



Verify after download항목을 체크 해제하고 Upgrade버튼을 눌러 업그레이드를 시작한다.

모든게 정상적이라면 Success 라는 메세지가 표시될 것이다.



이제 USB선을 제거했다가 다시 연결하면 장치 관리자에 새로운 COM포트가 만들어져 있을 것이다.

이제 PX4FMU의 부트로더가 정상적으로 업로드 된 것이다.


전원을 인가하면 노란색 LED가 10HZ 정도로 깜빡거리는 것을 확인할 수 있다.




다음에는 PX4IO 칩에 부트로더를 올리고 펌웨어를 다운로드 하는 과정을 알아보자.

반응형
반응형

PX4Firmware 를 빌드하는 과정을 정리하였다.

px4/modules/PX4Firmwares 안에는 펌웨어를 빌드하는 소스들이 포함되어있다.

이 소스코드를 빌드하기 위해서는 먼저 cmake 가 있어야 한다.

그래서 다음과 같이 cmake를 설치한다.


brew install cmake


그럼 다음과 같이 설치가 진행된다.


==> Auto-updated Homebrew!
Updated Homebrew from  to .
Updated 1 tap (homebrew/core).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/cmake-3.6.2.yosemite.bottle
######################################################################## 100.0%
==> Pouring cmake-3.6.2.yosemite.bottle.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/cmake
==> Summary
🍺  /usr/local/Cellar/cmake/3.6.2: 2,028 files, 28M



다시 make를 하면

make px4fmu-v2_default


아래와 같이 에러를 내뿜는다.

cp: /Users/********************/px4/ardupilot/modules/PX4Firmware/NuttX/.: No such file or directory
make[3]: *** [src/modules/px4iofirmware/nuttx_copy_px4io-v2.stamp] Error 1
make[2]: *** [src/modules/px4iofirmware/CMakeFiles/__nuttx_copy_px4io-v2.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
[  5%] Generating airframes.xml
Running from the source directory
Traceback (most recent call last):
  File "dsdl_compiler/libuavcan_dsdlc", line 59, in <module>
    from libuavcan_dsdl_compiler import run as dsdlc_run
  File "/Users/*****************/px4/ardupilot/modules/PX4Firmware/src/modules/uavcan/libuavcan/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py", line 17, in <module>
    from uavcan import dsdl
ImportError: No module named uavcan
make[3]: *** [src/modules/uavcan/libuavcan/libuavcan/CMakeFiles/libuavcan_dsdlc] Error 1
make[2]: *** [src/modules/uavcan/libuavcan/libuavcan/CMakeFiles/libuavcan_dsdlc.dir/all] Error 2
[  5%] Generating uORB topic headers
Scanning source path /Users/*****************/px4/ardupilot/modules/PX4Firmware/ROMFS/px4fmu_common/init.d
Scanning source path /Users/*****************/px4/ardupilot/modules/PX4Firmware/src
Creating XML file airframes.xml
All done!
Creating XML file parameters.xml
All done!
[  5%] Built target xml_gen
[  5%] Built target msg_gen
make[1]: *** [all] Error 2
make: *** [px4fmu-v2_default] Error 2



다시 또 검색...

https://groups.google.com/forum/#!topic/px4users/xImLJlrK1aU 


여기에서 make 하기 전에 "git submodule update --init --recursive --force" 를 해서 성공했다는 내용을 보고 다시 해본다

아마도 git 서브모듈이 없어서 그런가 본데...

이번에는 다른 에러가 나온다.

cp: /Users/kyubot_macmini2/px4/ardupilot/modules/PX4Firmware/NuttX/.: No such file or directory
make[3]: *** [nuttx_copy_px4fmu-v2.stamp] Error 1
make[2]: *** [CMakeFiles/__nuttx_copy_px4fmu-v2.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
[  5%] Built target msg_gen
cp: /Users/kyubot_macmini2/px4/ardupilot/modules/PX4Firmware/NuttX/.: No such file or directory
make[3]: *** [src/modules/px4iofirmware/nuttx_copy_px4io-v2.stamp] Error 1
make[2]: *** [src/modules/px4iofirmware/CMakeFiles/__nuttx_copy_px4io-v2.dir/all] Error 2
Running from the source directory
[  5%] Built target libuavcan_dsdlc
make[1]: *** [all] Error 2
make: *** [px4fmu-v2_default] Error 2



위 에러는 PX4Firmware 폴더 안에 NuttX 소스가 없어서 발생하는 에러였다.

NuttX를 가져오기 위해 https://github.com/PX4/NuttX 로 가서 git clone 할 주소를 찾는다.


sudo git clone https://github.com/PX4/NuttX.git ./NuttX


명령어를 입력하면 해당 Repository에서 NuttX 를 다운받기 시작한다.

Cloning into '/NuttX'...
remote: Counting objects: 232592, done.
remote: Total 232592 (delta 0), reused 0 (delta 0), pack-reused 232591
Receiving objects: 100% (232592/232592), 66.45 MiB | 1.98 MiB/s, done.
Resolving deltas: 100% (189334/189334), done.
Checking connectivity... done
Checking out files: 100% (7241/7241), done.



이렇게 나오면 성공

이제 다시 make px4fmu-v2_default 를 해봤더니....

/Users/XXXXXXXXXX/px4/ardupilot/modules/PX4Firmware/src/drivers/oreoled/oreoled.cpp: In constructor 'OREOLED::OREOLED(int, int, bool, bool)':
/Users/XXXXXXXXXX/px4/ardupilot/modules/PX4Firmware/src/drivers/oreoled/oreoled.cpp:144:12: error: 'OREOLED::_num_inboot' will be initialized after [-Werror=reorder]
  uint8_t   _num_inboot;     ///< number of LEDs in bootloader
            ^
compilation terminated due to -Wfatal-errors.
cc1plus: all warnings being treated as errors
make[3]: *** [src/drivers/oreoled/CMakeFiles/drivers__oreoled.dir/oreoled.cpp.obj] Error 1
make[2]: *** [src/drivers/oreoled/CMakeFiles/drivers__oreoled.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
[ 52%] Building CXX object src/modules/mavlink/CMakeFiles/modules__mavlink.dir/mavlink_ftp.cpp.obj
[ 52%] Linking CXX static library libmodules__navigator.a
[ 52%] Built target modules__navigator
[ 53%] Building CXX object src/modules/mavlink/CMakeFiles/modules__mavlink.dir/mavlink_log_handler.cpp.obj
[ 54%] Linking CXX static library libdrivers__px4flow.a
[ 54%] Built target drivers__px4flow
[ 54%] Linking CXX static library libmodules__mavlink.a
[ 54%] Built target modules__mavlink
make[1]: *** [all] Error 2
make: *** [px4fmu-v2_default] Error 2



이렇게 나오면서 컴파일 에러가 뜬다...


2016/10/5

문제 해결 방법을 드디어 찾았다.

사실 너무 기초적인 부분인데 놓치고 있었던 부분이다. PX4Firmware는 Mission Planner의 버전과는 전혀 다른 펌웨어였던 것이다.

http://ardupilot.org/dev/docs/building-px4-with-make-on-mac.html 이 링크에 설명된 설치 빌드 방법은 말 그대로 Ardupilot 기반의 px4 펌웨어를 빌드하기 위한 방법이고

PX4Firmware는 전혀 별개로 QGroundControl 혹은 QGC에서 사용하는 펌웨어인것이다.

따라서 PX4Firmware는 

https://github.com/PX4/Firmware 에 있는 펌웨어를 빌드해야 된다.

여기에 있는 서브모듈에는 NuttX가 포함되어 있다. 따라서 이 Repository 를 Checkout 해야된다.

다음 명령어로 Git Clone을 수행한다.


<수정 16/10/18>

git clone https://github.com/PX4/Firmware.git ./PX4Firmware

위 방법은 가장 최신의 master 로부터 소스를 다운받는데 빌드하여 적용한 결과 Arming/Safety Switch에 약간의 Bug 가 있는듯 하여 안정성이 검증된 Stable 브렌치로 받는걸 추천한다.

방법은 다음과 같다.


git clone -b stable https://github.com/PX4/Firmware.git ./myPX4


</수정 16/10/18>


<추가 16/10/16 >

새로 생성된 폴더에 들어가서 다음을 수행한다.


git submodule init

git submodule update


</추가 16/10/16>



이제 간단히 아래 명령어를 실행하여 빌드한다.


make px4fmu-v2_default


다음과 같이 아무런 문제없이 빌드가 될것이다.

[100%] Building C object src/modules/systemlib/CMakeFiles/modules__systemlib.dir/up_cxxinitialize.c.obj
[100%] Building CXX object src/modules/uavcan/CMakeFiles/modules__uavcan.dir/sensors/gnss.cpp.obj
[100%] Building C object src/modules/systemlib/CMakeFiles/modules__systemlib.dir/hx_stream.c.obj
[100%] Building CXX object src/modules/uavcan/CMakeFiles/modules__uavcan.dir/sensors/mag.cpp.obj
[100%] Linking CXX static library libmodules__systemlib.a
[100%] Built target modules__systemlib
[100%] Building CXX object src/modules/uavcan/CMakeFiles/modules__uavcan.dir/sensors/baro.cpp.obj
[100%] Linking CXX static library libmodules__uavcan.a
[100%] Built target modules__uavcan
Scanning dependencies of target firmware_nuttx
[100%] Building C object src/firmware/nuttx/CMakeFiles/firmware_nuttx.dir/builtin_commands.c.obj
[100%] Linking CXX executable firmware_nuttx
[100%] Built target firmware_nuttx
Scanning dependencies of target build_firmware_px4fmu-v2
[100%] Generating nuttx-px4fmu-v2-default.px4
[100%] Built target build_firmware_px4fmu-v2


이제 보드에 업로드를 하기 위해 다음 명령을 수행한다.


make px4fmu-v2_default upload


100%가 뜨고 USB커넥터를 보드에 연결하면 펌웨어를 다운로드하기 시작한다.


Loaded firmware for 9,0, size: 1023964 bytes, waiting for the bootloader...
If the board does not respond within 1-2 seconds, unplug and re-plug the USB connector.
Found board 9,0 bootloader rev 4 on /dev/tty.usbmodem1
50583400 00ac2600 00100000 00ffffff ffffffff ffffffff ffffffff ffffffff 47ec3b0c e8d261a2 2ed0636a cd1743c3 2019a208 d29d10c8 9eb3b46d 81981251 6287223e 280bd062 87f672b1 2dab8b7b 5438385e a7b19042 cee6035d 0e696c21 57b39769 701d3d25 8720e20a 5aff58bf 7d0dc680 386c0451 3d1b6f15 aa8f64fb 68b3f90f 46547f92 3dd9a6ad bc11d751 7ebcf038 0600292f 0627b65b e0f21ec6 ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff type: PX4
idtype: =00
vid: 000026ac
pid: 00000010
coa: R+w7DOjSYaIu0GNqzRdDwyAZogjSnRDInrO0bYGYElFihyI+KAvQYof2crEtq4t7VDg4XqexkELO5gNdDmlsIVezl2lwHT0lhyDiClr/WL99DcaAOGwEUT0bbxWqj2T7aLP5D0ZUf5I92aatvBHXUX688DgGACkvBie2W+DyHsY=

sn: 002400233034510636353832

Erase  : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.

[100%] Built target upload


이제 모든 설치가 완료되었다.

이번에 빌드한 펌웨어는 Mission Planner에서 사용할 수 없고 QGC에서 설정해야 한다.


이상....


반응형
반응형

빌드가 완료된 펌웨어를 픽스호크에 업로드 하는 방법을 알아보자.


mac에서 펌웨어를 업로드 하는 방법은 다음 링크의 자료를 참고하였다.

http://www.lambdrive.com/depot/Robotics/Controller/Firmware/ArduPilot/Building-ArduPilot-on-Mac.html#upload-compiled-firmware-to-your-px4-board


여기에 적힌 빌드 방식은 ArduPilot에 소개된 방법과 대부분 유사하나 약간의 차이가 있다.


빌드하기


ccache 를 설치하여 컴파일 속도를 높인다.

brew install ccache
ln -s ccache /usr/local/bin/gcc
ln -s ccache /usr/local/bin/g++
ln -s ccache /usr/local/bin/cc
ln -s ccache /usr/local/bin/c++


공식 가이드에 따라 make를 두번 수행한다. (첫번째는 PX4Firmware와  Nuttex를 2번째는 ArduCopter 를 빌드한다)

make px4-v2
make px4-v2


마지막으로 pixhawk를 위한 arducopter 펌웨어를 빌드한다.

make px4-quad


이제 2개의 펌웨어가 생성되었다. ArduCopter-v2.px4는 PX4 오리지날 버전을 위한것이고 ArduCopter-v2.px4는 Pixhawk를 위한 것이다.

동시 빌드를 인가하고 Pixhawk Quad 펌웨어를 지정하기 위해 다음을 수행한다.

make px4-v2-quad -j2


다른 프레임 구성을 빌드하려면 [frame type]의 내용을 tri, hexa, y6, octa, octa-quad, heli등으로 대치한다.

make px4-clean
make px4-[frame type]

주의: make clean 은 non-px4 타겟만을 제거한다.


의존성 부분만 제거하기 위해서는 다음을 수행한다.

make px4-cleandep


컴파일된 펌웨어를 px4보드에 업로드 하기

make px4-quad-upload -j4


 Pixhawk를 위해서는 v2를 명시한다.

make px4-v2-quad-upload -j4


컴파일이 모두 완료되면 다음과 같은 화면이 뜨면서 연결을 기다리게 된다.

Loaded firmware for 9,0, size: 944040 bytes, waiting for the bootloader...

If the board does not respond within 1-2 seconds, unplug and re-plug the USB connector.


이제 Pixhawk에 usb를 연결한다.

그럼 아래와 같이 보드를 발견했다는 메세지가 뜨면서 펌웨어를 전송하기 시작한다.

Found board 9,0 bootloader rev 4 on /dev/tty.usbmodem1

50583400 00ac2600 00100000 00ffffff ffffffff ffffffff fff#######...

type: PX4

idtype: =00

vid: 000026ac

pid: 00000010

coa: SAq/4cjPVJG0qdaLmD9k3Yw2nmGJjx0yKjq9mkzCA2tDjbXm###....


sn: 002a003f30##############


Erase  : [====================] 100.0%

Program: [====================] 100.0%

Verify : [====================] 100.0%

Rebooting.


이제 미션플래너를 연결하고 정상적으로 펌웨어가 올라갔는지 확인하면 끝이다.



반응형

+ Recent posts