class TestEntity(crest.Entity): res = crest.Resource("float-resource", crest.Types.REAL) listres = crest.Resource("list-res", ["first", "TWO", "3.14abc"]) port = crest.Local(resource=res, value=314.13) port2 = crest.Local(resource=listres, value="TWO") state = current = crest.State() state2 = crest.State()
class TestEntity(crest.Entity): in_port = crest.Input(res, 12) in_port2 = crest.Input(res, 33) state = current = crest.State() other_state = crest.State() # the evaluation of the guard of these will be mocked anyway transA = crest.Transition(source=state, target=other_state, guard=(lambda self: True)) transB = crest.Transition(source=state, target=other_state, guard=(lambda self: True))
class TestEntity(crest.Entity): state = current = crest.State() second_state = crest.State() trans = crest.Transition(source=state, target=second_state, guard=(lambda self: True)) def __init__(self): api.add(self, "second_state", crest.State())
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() second_state = crest.State() update = crest.Update(state=second_state, target=port_out, function=(lambda self: 12345)) def __init__(self): api.add(self, "second_state", crest.State())
class TestEntity(crest.Entity): sub = TestSubEntity() inf = crest.Influence(source=sub.out1, target=sub.in1) active = current = crest.State() inactive = crest.State() up_active = crest.Update(state=active, target=sub.in2, function=(lambda self, dt: 0)) up_inactive = crest.Update(state=inactive, target=sub.in2, function=(lambda self, dt: 0))
class RootType(crest.Entity): stateA = current = crest.State() stateB = crest.State() inport = crest.Input(crest.Resource("watt", crest.REAL), 0) local = crest.Local(crest.Resource("watt", crest.REAL), 1234) local2 = crest.Local(crest.Resource("watt", crest.REAL), 1234) outport = crest.Output(crest.Resource("watt", crest.REAL), 3.14) trans = crest.Transition(source=stateA, target=stateB, guard=(lambda self: False)) inf = crest.Influence(source=inport, target=local, function=(lambda value: value * 2 + 15)) up = crest.Update(state=stateA, target=outport, function=(lambda self: 1337)) action = crest.Action(transition=trans, target=local2, function=(lambda self: self.local2 + 1))
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() second_state = crest.State() transition = crest.Transition(source=state, target=second_state, guard=(lambda self: True)) action = crest.Action(transition=transition, target=port_out, function=(lambda self: 12345)) def __init__(self): api.add(self, "port_out", crest.Output(res, 7777))
class TestEntity(crest.Entity): res = crest.Resource("float-resource", crest.Types.REAL) port = crest.Local(resource=res, value=3) secondPort = crest.Local(resource=res, value=3) count = crest.Local(resource=res, value=2) init = current = crest.State() other = crest.State() otherother = crest.State() count_state = crest.State() @crest.transition(source=init, target=other) def t1a(self): return self.port.value >= 10 @crest.transition(source=init, target=otherother) def t1b(self): return self.port.value >= 10 @crest.transition(source=other, target=count_state) def t2a(self): return self.port.value >= 30 @crest.transition(source=otherother, target=count_state) def t2b(self): return self.port.value >= 50 @crest.transition(source=count_state, target=init) def t_count(self): return True @crest.update(state=[init, other], target=port) def increase_port(self, dt): return self.port.value + dt @crest.update(state=[init, other, otherother], target=secondPort) def increase_secondport(self, dt): return self.secondPort.value + dt @crest.update(state=otherother, target=port) def increase_port_otherother(self, dt): return self.port.value + 2 * dt @crest.update(state=count_state, target=count) def update_count(self, dt): return self.count.value + 1 @crest.update(state=count_state, target=port) def reset_port(self, dt): return 0
class Test(crest.Entity): s1 = current = crest.State() s2 = crest.State() s3 = crest.State() @crest.transition(source=[s1, s3], target=s2) def t1(self): return True t2 = crest.Transition(source=s2, target=s3, guard=(lambda self: True)) t3 = crest.Transition(source=[s3, s2], target=s1, guard=(lambda self: False))
class TestSubEntity(crest.Entity): state = current = crest.State() port_in = crest.Input(res, 111) port_in2 = crest.Input(res, 222) port_out = crest.Output(res, 11111) port_out2 = crest.Output(res, 22222)
class TestEntity(crest.Entity): port_in = crest.Input(res, 1234) state = current = crest.State() sub = SubEntity() influence = crest.Influence(source=port_in, target=sub.sub_in) def __init__(self): api.add(self, "sub", SubEntity())
class TestEntity(crest.Entity): port_in = crest.Input(res, 1234) port_out = crest.Output(res, 987) state = current = crest.State() influence = crest.Influence(source=port_in, target=port_out) def __init__(self): api.add(self, "port_out", crest.Output(res, 5555))
class TestEntity(crest.Entity): state = current = crest.State() local = crest.Local(res, 9999) local2 = crest.Local(res, 8888) sub1 = TestSubEntity() sub2 = TestSubEntity()
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() sub = SubEntity() influence = crest.Influence(source=sub.sub_out, target=port_out) def __init__(self): api.add(self, "sub", SubEntity())
class TestEntity(crest.Entity): port_in = crest.Input(res, 1234) sub = SubEntity() state = current = crest.State() update = crest.Update(state=state, target=sub.sub_in, function=(lambda self: 12345)) def __init__(self): api.add(self, "sub", SubEntity())
class GerminationBox(crest.Entity): switch = crest.Input(resource=onOff, value="on") temperature = crest.Local(resource=celsius, value=22) state = current = crest.State() @crest.update(state=state, target=temperature) def update_temp(self, dt): if self.switch.value == "on": # don't exceed 40 (this is the maximum temperature) return min(40, self.temperature.value + 0.5 * dt) else: # don't go below 22 (minimum = current room temperature) return max(22, self.temperature.value - 0.25 * dt)
def test_override_state_in__init__updates_current_state_to_new_state(self): res = crest.Resource("test", crest.REAL) newstate = crest.State() class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() def __init__(self): api.add(self, "state", newstate) entity = TestEntity() self.assertEqual(newstate, entity.current)
def __init__(self): api.add(self, "second_state", crest.State())
class TestSystem(crest.Entity): switch = crest.Input(resource=onOff, value="on") timer = crest.Local(resource=res_time, value=0) germinationbox_one = GerminationBox() germinationbox_two = GerminationBox() off = current = crest.State() on = crest.State() pause = crest.State() boxOne = crest.State() boxTwo = crest.State() # transitions @crest.transition(source=[on, boxOne, boxTwo, pause], target=off) def on_to_off(self): return self.switch.value == "off" @crest.transition(source=off, target=on) def off_to_on(self): return self.switch.value == "on" @crest.transition(source=[boxOne, boxTwo, pause], target=on) def return_to_on(self): return self.timer.value <= 0 @crest.transition(source=on, target=[boxOne, boxTwo]) def on_to_box(self): return self.timer.value <= 0 @crest.transition(source=on, target=pause) def on_to_pause(self): return self.timer.value <= 0 """ updates """ @crest.update(state=[on, boxOne, boxTwo, pause], target=timer) def reduce_timer(self, dt): return max(0, self.timer.value - dt) @crest.update(state=boxOne, target=germinationbox_one.switch) def turn_on_boxOne(self, dt): return "on" @crest.update(state=[on, pause, off, boxTwo], target=germinationbox_one.switch) def turn_off_boxOne(self, dt): return "off" @crest.update(state=boxTwo, target=germinationbox_two.switch) def turn_on_boxTwo(self, dt): return "on" @crest.update(state=[on, pause, off, boxOne], target=germinationbox_two.switch) def turn_off_boxTwo(self, dt): return "off" """ transition actions """ @crest.action(transition=off_to_on, target=timer) def set_timer_zero_when_turn_on(self): return 0 @crest.action(transition=on_to_box, target=timer) def set_timer_thirty(self): return 30 @crest.action(transition=on_to_pause, target=timer) def set_timer_ten(self): return 10
class Subtype(self.basetype): stateA = crest.State() # careful, we haven't changed current here. This shouldn't cause issues though :-/ stateB = crest.State()
class Subtype(self.basetype): stateA = crest.State() stateB = crest.State()
class Test(crest.Entity): A = current = crest.State() port = crest.Input(crest.Resource("watt", crest.REAL), 3.14)
class TestEntity(crest.Entity): state = current = crest.State() sub1 = TestSubEntity() sub2 = TestSubEntity()
class SubEntity(crest.Entity): state = current = crest.State() sub_in = crest.Input(res, 111)
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() def __init__(self): api.add(self, "state", newstate)
class Test(crest.Entity): A = current = crest.State() B = crest.State() C = crest.State()
class SubEntity(crest.Entity): state = current = crest.State() sub_out = crest.Output(res, 111)
class Subtype(self.basetype): stateA = current = crest.State()