Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New language #116

Merged
merged 24 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d2d5566
[language] New plan language
Tigul Nov 22, 2023
4457748
[language] Improvements for parallel execution
Tigul Nov 23, 2023
4f9fb42
[language/giskard] new parallel mechanism
Tigul Nov 24, 2023
3f62daa
[giskard] thread safty
Tigul Nov 27, 2023
8314dd1
[giskard] Finishes giskard interface for parallel execution
Tigul Nov 28, 2023
617acbe
[language] Finished implementation for language and tests
Tigul Nov 29, 2023
fdd1950
[language] More tests for language
Tigul Nov 29, 2023
d95ddb1
[examples] added language example
Tigul Dec 1, 2023
8fba643
[language] Finishing refactor of language code
Tigul Dec 1, 2023
259a923
[language] Fix for designators that do not use giskard
Tigul Dec 5, 2023
d02f05b
[giskard] Added check to prevent multiple constraints with the same j…
Tigul Dec 7, 2023
6b0ab40
[language] Interrupts and Monitors
Tigul Dec 8, 2023
9fe9a38
[language] Monitors
Tigul Dec 11, 2023
7ec964c
[fluent] Removed Macropy dependency
Tigul Dec 13, 2023
4b2c4fd
[language] Finished monitor implementation
Tigul Dec 13, 2023
9aa63c9
[language] Added Repeat expression
Tigul Dec 13, 2023
146a408
[tests] added more language tests
Tigul Dec 13, 2023
52a8b91
[general] Removed Macropy submodule and code imports
Tigul Dec 13, 2023
ac5a28c
[language] improved interrupt
Tigul Dec 22, 2023
c5ac942
[examples] Added repeat and monitor to language example
Tigul Jan 10, 2024
f29e033
[tests] fixed tests for monitors and renamed local transfomer tests
Tigul Jan 12, 2024
1f99c65
[language] clean up
Tigul Jan 12, 2024
f824a49
Merge branch 'dev' of github.com:cram2/pycram into new-language
Tigul Jan 12, 2024
9eb2314
[tests] Fixed local transforer for new bullet test case
Tigul Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[language] Monitors
Tigul committed Dec 11, 2023
commit 9fe9a38f5f3d6e1ce2a20812f81772f9c0c3e37b
54 changes: 50 additions & 4 deletions src/pycram/language.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# used for delayed evaluation of typing until python 3.11 becomes mainstream
from __future__ import annotations

import time
from typing import Iterable, Optional, Callable, Dict, Any, List
from anytree import NodeMixin, Node, PreOrderIter

@@ -105,7 +106,18 @@ def __xor__(self, other: Language) -> TryAll:
return TryAll(parent=None, children=(self, other)).simplify()

def __rshift__(self, other):
return Monitor(parent=None, children=(self, other)).simplify()
"""
:param other:
:return:
"""
if type(self) == Monitor:
self.children = [other]
return self
elif type(other) == Monitor:
other.children = [self]
return other
# return Monitor(parent=None, children=(self, other)).simplify()

def simplify(self) -> Language:
"""
@@ -130,6 +142,8 @@ def simplify(self) -> Language:
"""
for node in PreOrderIter(self.root):
for child in node.children:
if type(child) == Monitor:
continue
if type(node) is type(child):
self.merge_nodes(node, child)
return self.root
@@ -151,14 +165,46 @@ def interrupt(self):


class Monitor(Language):
def __init__(self, parent=None, children=None, condition=None):
super().__init__(parent, children)
"""
Monitors a Language Expression and interrupts it when the given condition is evaluated to True.
Behaviour:
This Monitor is attached to a language expression, when perform on this Monitor is called it will start a new
thread which continuously checks if the condition is True. When the condition is True the interrupt function of
the child will be called.
"""
def __init__(self, condition=None):
"""
When initializing a Monitor a condition must be provided. The condition is a callable which returns to True or
False.
:param condition: The condition upon which the Monitor should interrupt the attached language expression.
"""
super().__init__(None, None)
self.condition = condition

def perform(self):
...
"""
Behavior of the Monitor, starts a new Thread which checks the condition and then performs the attached language
expression
:return: The result of the attached language expression
"""
def check_condition():
while not self.condition():
time.sleep(0.1)
for child in self.children:
child.interrupt()

t = threading.Thread(target=check_condition)
t.start()
return self.children[0].perform()
t.join()

def interrupt(self):
"""
Calls interrupt for each child
"""
for child in self.children:
child.interrupt()