Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CPS_project_group13
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hierck, J.J. (Jelle, Student M-BME,M-EMSYS)
CPS_project_group13
Commits
e33aa200
Commit
e33aa200
authored
4 years ago
by
Dominik HAefner
Browse files
Options
Downloads
Plain Diff
Added Virtual Map in 'Explore'and added possible Pathfinding in 'test'
parents
bd23af94
62d14396
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mappingbot/bluetooth.py
+73
-0
73 additions, 0 deletions
mappingbot/bluetooth.py
mappingbot/driving.py
+35
-14
35 additions, 14 deletions
mappingbot/driving.py
mappingbot/encoder.py
+12
-12
12 additions, 12 deletions
mappingbot/encoder.py
with
120 additions
and
26 deletions
mappingbot/bluetooth.py
0 → 100644
+
73
−
0
View file @
e33aa200
from
bluepy.btle
import
Scanner
scanner
=
Scanner
()
i
=
0
d
=
0
#m = 0
#h = 0
values
=
[]
oldAverage
=
0
average
=
0
found
=
False
while
True
:
devices
=
scanner
.
scan
(
0.4
)
# low delay will result in a lot of iterations without RSSI
for
device
in
devices
:
if
device
.
addr
==
"
30:4b:07:ff:e0:3e
"
:
#found = True
#h += 1
# Calculate rolling average
values
.
append
(
device
.
rssi
)
valSum
=
sum
(
values
)
if
len
(
values
)
>
20
:
values
.
pop
(
0
)
valSum
=
sum
(
values
)
oldAverage
=
average
average
=
valSum
/
(
len
(
values
))
# if oldAverage != 0:
# #print(average/oldAverage)
# if average/oldAverage > 1.01:
# i += 1
# d = 0
# elif average/oldAverage < 0.99:
# d += 1
# i = 0
# else:
# i = 0
# d = 0
#
# if d > 1:
# # Moving away
# print("decreasing")
# elif i > 1:
# # Coming closer
# print("increasing")
#
# print("D:" + str(d) + " I:" + str(i))
if
average
>
oldAverage
:
d
+=
1
i
=
0
elif
average
<
oldAverage
:
i
+=
1
d
=
0
if
d
>
3
:
# Coming closer
print
(
"
decreasing
"
)
elif
i
>
3
:
# Moving away
print
(
"
increasing
"
)
print
(
"
D:
"
+
str
(
d
)
+
"
I:
"
+
str
(
i
))
#print(values)
#print("Average: " + str(average))
# else:
# m += 1
# print(m)
# if not found:
# m += 1
# else:
# found = False
# print("Hit: " + str(h) + "Miss: " + str(m))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mappingbot/driving.py
+
35
−
14
View file @
e33aa200
# Libraries
#import RPi.GPIO as GPIO
import
time
import
Encoder
from
e
ncoder
from
encoder
import
E
ncoder
#import PWMoutputFunction
# GPIO Mode (BOARD / BCM)
...
...
@@ -23,9 +23,8 @@ class Driving:
self
.
rotationspeed
=
0.2
#speed in PWM percentage
self
.
leftPWM
=
0
self
.
rightPWM
=
0
self
.
encoderLeft
=
Encoder
(
left
,
23
)
self
.
encoderRight
=
Encoder
(
right
,
24
)
self
.
encoderLeft
=
Encoder
(
name
=
"
encoder1
"
,
encoder_pin
=
23
)
self
.
encoderRight
=
Encoder
(
name
=
"
encoder1
"
,
encoder_pin
=
24
)
def
stop
(
self
):
self
.
speed
=
0
...
...
@@ -83,29 +82,51 @@ class Driving:
self
.
currentPulseCountRight
=
self
.
encoderRight
.
get_pulse_count
()
if
self
.
currentPulseCountLeft
>=
self
.
setpointPulseCountLeft
:
self
.
leftPWM
=
0
self
.
leftPWM
=
0
elif
self
.
currentPulseCountLeft
>=
self
.
setpointPulseCountLeft
-
5
:
self
.
leftPWM
=
self
.
speed
*
0.5
elif
self
.
currentPulseCountLeft
>=
self
.
setpointPulseCountLeft
-
2
:
elif
self
.
currentPulseCountLeft
>=
self
.
setpointPulseCountLeft
-
2
:
self
.
leftPWM
=
self
.
speed
*
0.1
else
else
:
self
.
leftPWM
=
self
.
speed
if
self
.
setpoi
ntPulseCountRight
>=
self
.
curre
ntPulseCountRight
:
self
.
rightPWM
=
0
#if self.setpointPulseCountRight >= self.currentPulseCountRight:
if
self
.
curre
ntPulseCountRight
>=
self
.
setpoi
ntPulseCountRight
:
self
.
rightPWM
=
0
elif
self
.
currentPulseCountRight
>=
self
.
setpointPulseCountRight
-
5
:
self
.
rightPWM
=
self
.
speed
*
0.5
elif
self
.
currentPulseCountRight
>=
self
.
setpointPulseCountRight
-
2
:
elif
self
.
currentPulseCountRight
>=
self
.
setpointPulseCountRight
-
2
:
self
.
rightPWM
=
self
.
speed
*
0.1
else
else
:
self
.
rightPWM
=
self
.
speed
# safty control, left and right PWM should always be the same. If not, chose the smaler one
# safty control, left and right PWM should always be the same. If not, cho
o
se the smal
l
er one
if
self
.
leftPWM
>
self
.
rightPWM
:
self
.
leftPWM
=
self
.
rightPWM
if
self
.
rightPWM
>
self
.
leftPWM
:
self
.
rightPWM
=
self
.
leftPWM
return
self
.
leftPWM
,
self
.
rightPWM
,
self
.
directionLeftWheel
,
self
.
directionRightWheel
try
:
motor
=
Driving
()
motor
.
__init__
()
leftPin
=
GPIO
.
PWM
(
LEFTMOTOR
,
50
)
leftPin
.
start
(
0
)
motor
.
driveForward
(
30
,
1
)
while
True
:
leftDC
,
rightDC
,
dir1
,
dir2
=
motor
.
getPWM
()
leftPin
.
ChangeDutyCycle
(
leftDC
)
print
(
leftDC
)
time
.
sleep
(
0.01
)
except
KeyboardInterrupt
:
# Exit by pressing CTRL + C
leftPin
.
stop
()
GPIO
.
cleanup
()
print
(
"
Measurement stopped by User
"
)
finally
:
leftPin
.
stop
()
GPIO
.
cleanup
()
return
self
.
leftPWM
,
self
.
rightPWM
,
self
.
directionLeftWheel
,
self
.
directionRightWheel
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mappingbot/encoder.py
+
12
−
12
View file @
e33aa200
...
...
@@ -62,16 +62,16 @@ class Encoder:
# Initialize the interrupt
GPIO
.
add_event_detect
(
self
.
encoder_pin
,
GPIO
.
BOTH
,
callback
=
self
.
callback_encoder
,
bouncetime
=
10
)
try
:
encoder1
=
Encoder
(
name
=
"
encoder1
"
,
encoder_pin
=
4
)
encoder1
.
init_callback
()
while
True
:
print
(
encoder1
.
get_pulse_count
())
print
(
encoder1
.
get_speed
())
time
.
sleep
(
1
)
except
KeyboardInterrupt
:
# Exit by pressing CTRL + C
GPIO
.
cleanup
()
print
(
"
Measurement stopped by User
"
)
finally
:
GPIO
.
cleanup
()
#
try:
#
encoder1 = Encoder(name="encoder1", encoder_pin=4)
#
encoder1.init_callback()
#
while True:
#
print(encoder1.get_pulse_count())
#
print(encoder1.get_speed())
#
time.sleep(1)
#
except KeyboardInterrupt: # Exit by pressing CTRL + C
#
GPIO.cleanup()
#
print("Measurement stopped by User")
#
finally:
#
GPIO.cleanup()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment