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-19 10:40:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0b5bed6bdd4b3e2d0a1886224d5efcb71653eaa2
0b5bed6b
1 parent
f1c0254b
Upload new file
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
step3/step3.py
step3/step3.py
0 → 100644
View file @
0b5bed6
#step 3 : slave드론의 접촉에 의한 반응으로 master드론 움직이기
import
CoDrone
import
keyboard
from
CoDrone.system
import
Direction
from
CoDrone.system
import
Mode
from
time
import
sleep
errorRange
=
50
# 오차범위
heightRange
=
30
# 움직였다고 판단할 거리 height
posiRange
=
10
# position (x, y) 변화 인지 거리
def
setHeight
(
_sHeight
,
_master
):
while
True
:
_mHeight
=
_mlave
.
get_height
()
if
_sHeight
-
errorRange
<=
_mHeight
<=
_sHeight
+
errorRange
:
print
(
'[hit]'
)
return
elif
_mHeight
<
_sHeight
-
errorRange
:
_master
.
go
(
Direction
.
UP
)
sleep
(
0.2
)
print
(
'[up]'
)
elif
_mHeight
>
_sHeight
+
errorRange
:
_master
.
go
(
Direction
.
DOWN
)
sleep
(
0.2
)
print
(
'[down]'
)
def
main
():
master
=
CoDrone
.
CoDrone
()
master
.
connect
(
"None"
,
"COM3"
,
False
)
slave
=
CoDrone
.
CoDrone
()
slave
.
connect
(
"None"
,
"COM5"
,
False
)
master
.
takeoff
()
#master 드론 이륙
slave
.
takeoff
()
#slave 드론 이륙
slave
.
hover
(
60
)
bHeight
=
slave
.
get_height
()
# bHeight = slave의 높이
# slave의 이전 좌표값(움직임 추적용) 초기화
bHeight
=
0
while
True
:
# master
mPosition
=
master
.
get_opt_flow_position
()
# 상대좌표 (시작 0,0)
mHeight
=
master
.
get_height
()
# master고도
# slave
sPosition
=
slave
.
get_opt_flow_position
()
sHeight
=
slave
.
get_height
()
# slave고도
print
(
"master [x={} y={} z={}] slave [x={} y={} z={}]"
.
format
(
mPosition
.
X
,
mPosition
.
Y
,
mHeight
,
sPosition
.
X
,
sPosition
.
# slave의 전 높이 대비 heightRange 만큼의 차이가 있으면 master가 움직이도록
if
abs
(
sHeight
-
bHeight
)
>
heightRange
:
print
(
'[height change!]'
)
setHeight
(
sHeight
,
master
)
# master의 높이 이동
# slave의 이전 좌표값 저장
bHeight
=
sHeight
if
__name__
==
'__main__'
:
main
()
Please
register
or
login
to post a comment