Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
JSH_Project7
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이유진
2020-06-15 22:02:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
40e72a1b4908a6e855f5541513428c8c4d31ebd6
40e72a1b
1 parent
d120b2af
드론 높이 조정
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
7 deletions
yujin_test/setHeight.py
yujin_test/step1.py
yujin_test/setHeight.py
0 → 100644
View file @
40e72a1
# 드론 높이조정 테스트 코드 (드론 1대용)
import
CoDrone
from
CoDrone.system
import
Direction
from
time
import
sleep
errorRange
=
50
# 오차범위
def
getPosition
(
drone
):
position
=
drone
.
get_opt_flow_position
()
# 상대좌표 (시작 0,0)
height
=
drone
.
get_height
()
# 고
print
(
"x={} y={} z={}"
.
format
(
position
.
X
,
position
.
Y
,
height
))
# 단위(mm)
def
setHeight
(
_mHeight
,
_slave
):
while
True
:
_sHeight
=
_slave
.
get_height
()
if
_mHeight
-
errorRange
<=
_sHeight
<=
_mHeight
+
errorRange
:
print
(
'hit'
)
return
elif
_sHeight
<
_mHeight
-
errorRange
:
_slave
.
go
(
Direction
.
UP
)
getPosition
(
_slave
)
sleep
(
0.2
)
print
(
'up'
)
elif
_sHeight
>
_mHeight
+
errorRange
:
_slave
.
go
(
Direction
.
DOWN
)
getPosition
(
_slave
)
sleep
(
0.2
)
print
(
'down'
)
def
main
():
drone
=
CoDrone
.
CoDrone
()
drone
.
connect
()
oHeight
=
200
# 목적 높이
drone
.
takeoff
()
getPosition
(
drone
)
setHeight
(
oHeight
,
drone
)
getPosition
(
drone
)
drone
.
hover
(
3
)
print
(
'Land'
)
drone
.
land
()
if
__name__
==
'__main__'
:
main
()
yujin_test/step1.py
View file @
40e72a1
...
...
@@ -4,17 +4,24 @@ from CoDrone.system import Direction
from
time
import
sleep
errorRange
=
50
# 오차범위
moveRange
=
150
# 움직였다고 판단할 거리
def
setHeight
(
_mHeight
,
_slave
):
while
True
:
_sHeight
=
_slave
.
get_height
()
if
_mHeight
-
100
<=
_sHeight
<=
_mHeight
+
100
:
if
_mHeight
-
errorRange
<=
_sHeight
<=
_mHeight
+
errorRange
:
print
(
'hit'
)
return
elif
_sHeight
<
_mHeight
-
100
:
elif
_sHeight
<
_mHeight
-
errorRange
:
_slave
.
go
(
Direction
.
UP
)
sleep
(
0.2
)
elif
_sHeight
>
_mHeight
+
100
:
print
(
'up'
)
elif
_sHeight
>
_mHeight
+
errorRange
:
_slave
.
go
(
Direction
.
DOWN
)
sleep
(
0.2
)
print
(
'down'
)
def
main
():
...
...
@@ -40,7 +47,7 @@ def main():
# 키보드로 콘솔창에 'q'를 누르면 드론이 착륙하게 만드는 코드인데
# 한 번 성공하고 그 이후로 안 되네요
# $pip3 install keyboard
# 로
깔아
야 합니다.
# 로
keyboard를 설치한 다음 실행해
야 합니다.
if
keyboard
.
is_pressed
(
'q'
):
print
(
'드론을 착륙시킵니다.'
)
slave
.
land
()
...
...
@@ -49,11 +56,11 @@ def main():
# print('emergency_stop')
break
# master의 전 높이 대비 +-
150
의 차이가 있으면 slave가 움직이도록
if
mHeight
>
bHeight
+
150
or
mHeight
<
bHeight
-
150
:
# master의 전 높이 대비 +-
moveRange 만큼
의 차이가 있으면 slave가 움직이도록
if
mHeight
>
bHeight
+
moveRange
or
mHeight
<
bHeight
-
moveRange
:
setHeight
(
mHeight
,
slave
)
bHeight
=
mHeight
bHeight
=
mHeight
# 이전 높이 저장
if
__name__
==
'__main__'
:
...
...
Please
register
or
login
to post a comment