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
1b696744
Commit
1b696744
authored
4 years ago
by
SiccoColijn
Browse files
Options
Downloads
Patches
Plain Diff
Included PWM
parent
a344012e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mappingbot/driving.py
+37
-15
37 additions, 15 deletions
mappingbot/driving.py
with
37 additions
and
15 deletions
mappingbot/driving.py
+
37
−
15
View file @
1b696744
# Libraries
import
RPi.GPIO
as
GPIO
import
time
import
Encoder
from
e
ncoder
from
encoder
import
E
ncoder
#import PWMoutputFunction
# GPIO Mode (BOARD / BCM)
GPIO
.
setmode
(
GPIO
.
BCM
)
print
(
GPIO
.
VERSION
)
LEFTMOTOR
=
17
GPIO
.
setup
(
LEFTMOTOR
,
GPIO
.
OUT
)
class
Driving
:
def
__init__
(
self
):
...
...
@@ -23,13 +25,11 @@ 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
def
driveForward
(
self
,
distance
,
speed
):
#reset pulse count
...
...
@@ -78,29 +78,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.
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