Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSPM_MecanumWheelCar
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
Edmund Jochim
CSPM_MecanumWheelCar
Commits
3e5801cb
Commit
3e5801cb
authored
5 months ago
by
Edmund Jochim
Browse files
Options
Downloads
Patches
Plain Diff
Added demo.py
parent
2d591b05
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python_Software/examples/demo.py
+81
-0
81 additions, 0 deletions
Python_Software/examples/demo.py
with
81 additions
and
0 deletions
Python_Software/examples/demo.py
0 → 100644
+
81
−
0
View file @
3e5801cb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
sys
import
os
import
time
import
pandas
as
pd
from
datetime
import
datetime
from
threading
import
Thread
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
..
'
)))
from
mecanumcarpy
import
MecanumCar
def
control_car
(
car
):
"""
Control the movement of the car.
"""
car
.
update_speed
(
100
)
car
.
move_forward
()
time
.
sleep
(
3
)
car
.
update_speed
(
110
)
car
.
move_back
()
time
.
sleep
(
3
)
car
.
update_speed
(
80
)
car
.
move_diagonally
(
direction
=
'
rb
'
)
time
.
sleep
(
3
)
car
.
stop
()
time
.
sleep
(
3
)
car
.
update_speed
(
70
)
car
.
move
(
direction
=
'
left
'
)
time
.
sleep
(
3
)
car
.
update_speed
(
127
)
car
.
send_rc_control
(
90
,
100
,
127
)
time
.
sleep
(
2
)
car
.
stop
()
def
print_state
(
car
,
duration
,
interval
=
1
):
"""
Print state information about the car every second.
"""
time
.
sleep
(
5
)
start_time
=
time
.
time
()
while
time
.
time
()
-
start_time
<
duration
-
5
:
print
(
f
"
Timestamp:
{
datetime
.
now
()
}
\n
"
)
print
(
f
"
Battery Voltage:
{
car
.
get_batteryVoltage
()
}
\n
"
)
print
(
f
"
Battery Percent:
{
car
.
get_batteryPercent
()
}
\n
"
)
print
(
f
"
Motor A:
{
car
.
get_motorA
()
}
\n
"
)
print
(
f
"
Motor B:
{
car
.
get_motorB
()
}
\n
"
)
print
(
f
"
Motor C:
{
car
.
get_motorC
()
}
\n
"
)
print
(
f
"
Motor D:
{
car
.
get_motorD
()
}
\n\n
"
)
time
.
sleep
(
interval
)
def
main
():
car
=
MecanumCar
()
car
.
send_keepalive
()
# Define duration for control and state collection
duration
=
60
# 60 seconds
# Start state collection in a separate thread
state_thread
=
Thread
(
target
=
print_state
,
args
=
(
car
,
duration
))
# Start car control in a separate thread
control_thread
=
Thread
(
target
=
control_car
,
args
=
(
car
,))
# Start both threads
state_thread
.
start
()
control_thread
.
start
()
# Wait for both threads to complete
control_thread
.
join
()
state_thread
.
join
()
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
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