Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
quadruped-reactive-walking
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Gepetto
quadruped-reactive-walking
Commits
98fe3e77
Commit
98fe3e77
authored
4 years ago
by
Pierre-Alexandre Leziart
Committed by
Pierre-Alexandre Leziart
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Files to test triggering the main loop with a periodic signal
parent
f2ce01bc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
loop.py
+31
-0
31 additions, 0 deletions
loop.py
test_loop.py
+38
-0
38 additions, 0 deletions
test_loop.py
with
69 additions
and
0 deletions
loop.py
0 → 100644
+
31
−
0
View file @
98fe3e77
import
signal
,
time
from
abc
import
ABCMeta
,
abstractmethod
## Code copied from mlp to avoid large dependency. Should be put in smaller package instead
class
Loop
(
metaclass
=
ABCMeta
):
"""
Astract Class to allow users to execute self.loop at a given frequency
with a timer while self.run can do something else.
"""
def
__init__
(
self
,
period
):
self
.
period
=
period
signal
.
signal
(
signal
.
SIGALRM
,
self
.
loop
)
signal
.
setitimer
(
signal
.
ITIMER_REAL
,
period
,
period
)
self
.
run
()
def
stop
(
self
):
signal
.
setitimer
(
signal
.
ITIMER_REAL
,
0
)
raise
KeyboardInterrupt
# our self.run is waiting for this.
def
run
(
self
):
# Default implementation: don't do anything
try
:
time
.
sleep
(
1e9
)
except
KeyboardInterrupt
:
pass
@abstractmethod
def
loop
(
self
,
signum
,
frame
):
...
This diff is collapsed.
Click to expand it.
test_loop.py
0 → 100644
+
38
−
0
View file @
98fe3e77
import
numpy
as
np
import
time
from
loop
import
Loop
class
SimulatorLoop
(
Loop
):
"""
Class used to call pybullet at a given frequency
"""
def
__init__
(
self
,
period
,
t_max
):
"""
Constructor
:param period: the time step
:param t_max: maximum simulation time
"""
self
.
t
=
0.0
self
.
t_max
=
t_max
self
.
period
=
period
def
trigger
(
self
):
super
().
__init__
(
self
.
period
)
def
loop
(
self
,
signum
,
frame
):
self
.
t
+=
self
.
period
if
self
.
t
>
self
.
t_max
:
self
.
stop
()
print
(
"
- Start loop -
"
)
print
(
"
- End loop -
"
)
if
__name__
==
"
__main__
"
:
# Start the control loop:
sim_loop
=
SimulatorLoop
(
1.0
,
10.0
)
sim_loop
.
trigger
()
print
(
"
-- FINAL --
"
)
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