print('started continuous transition') m = u_seq[0, :].size for i in range(N): u = u_seq[i, :].reshape(m, 1) x = A.dot(x) + B.dot(u) + K print('Discrete time: k = ' +str(i) ) print('\t u[' +str(i) +"]' = " +str(u.T) ) print('\t x[' +str(i) +"]' = " +str(x.T) +'\n') print('completed continuous transition iteration') return x x0 = np.array([0.5, 0.6]) start = find_discrete_state(x0, disc_dynamics.ppp) end = 14 start_poly = disc_dynamics.ppp.regions[start] end_poly = disc_dynamics.ppp.regions[end] if not is_inside(start_poly, x0): raise Exception('x0 \\notin start_poly') start_state = start end_state = end post = disc_dynamics.ts.states.post(start_state) print(post) if not end_state in post: raise Exception('end \\notin post(start)')
print('started continuous transition') m = u_seq[0, :].size for i in xrange(N): u = u_seq[i, :].reshape(m, 1) x = A.dot(x) + B.dot(u) + K print('Discrete time: k = ' + str(i)) print('\t u[' + str(i) + "]' = " + str(u.T)) print('\t x[' + str(i) + "]' = " + str(x.T) + '\n') print('completed continuous transition iteration') return x x0 = np.array([0.5, 0.6]) start = find_discrete_state(x0, disc_dynamics.ppp) end = 14 start_poly = disc_dynamics.ppp.regions[start] end_poly = disc_dynamics.ppp.regions[end] if not is_inside(start_poly, x0): raise Exception('x0 \\notin start_poly') start_state = 's' + str(start) end_state = 's' + str(end) post = disc_dynamics.ts.states.post(start_state) print(post) if not end_state in post: raise Exception('end \\notin post(start)')
work with only_mode_controlled.py - make a manual AOFTS from there. Send it to synth. Change env_augmented_open_fts2spec to call env_open_fts2spec and then append equil pts. Allow self_trans and see what controller happens Put !OUTSIDE inside env_spec. """ #jt_fts = synth.synthesize('jtlv', specs, env=abstMOS.ts, ignore_env_init=True, rm_deadends=False) gr_fts = synth.synthesize('gr1c', specs, env=abstMOS.ts,rm_deadends=True, ignore_env_init=True) #print (gr_fts) if not gr_fts.save('gr_fts.eps'): print(gr_fts) disc_dynamics=abstMOS ctrl=gr_fts Tc = [18.0] Th = [16.0] s0_part = find_discrete_state([Tc[0],Th[0]],disc_dynamics.ppp) #mach = synth.determinize_machine_init(ctrl,{'sys_actions':'on'}) # - to be used if we want a certain mode only sim_hor = 130 N=1 # N = number of steps between each sampled transition (s1, dum) = mach.reaction('Sinit', {'eloc': 's0'}) #(s1, dum) = mach.reaction(s1, {'on': 1}) for sim_time in range(sim_hor): sysnow=('regular',dum['sys_actions']) #sysnow = #find your mode (read from mach) for ind in range(N): x = np.dot( ssd.dynamics[sysnow].list_subsys[0].A, [Tc[-1],Th[-1]] ) + ssd.dynamics[sysnow].list_subsys[0].K.flatten() Tc.append(x[0])
#jt_fts = synth.synthesize('jtlv', specs, env=abstMOS.ts, ignore_env_init=True, rm_deadends=False) gr_fts = synth.synthesize('gr1c', specs, env=abstMOS.ts, rm_deadends=True, ignore_env_init=True) #print (gr_fts) if not gr_fts.save('gr_fts.eps'): print(gr_fts) disc_dynamics = abstMOS ctrl = gr_fts Tc = [18.0] Th = [16.0] s0_part = find_discrete_state([Tc[0], Th[0]], disc_dynamics.ppp) #mach = synth.determinize_machine_init(ctrl,{'sys_actions':'on'}) # - to be used if we want a certain mode only sim_hor = 130 N = 1 # N = number of steps between each sampled transition (s1, dum) = mach.reaction('Sinit', {'eloc': 's0'}) #(s1, dum) = mach.reaction(s1, {'on': 1}) for sim_time in range(sim_hor): sysnow = ('regular', dum['sys_actions']) #sysnow = #find your mode (read from mach) for ind in range(N): x = np.dot(ssd.dynamics[sysnow].list_subsys[0].A, [Tc[-1], Th[-1] ]) + ssd.dynamics[sysnow].list_subsys[0].K.flatten() Tc.append(x[0])
def test_find_controller_non_convex(): """Test that it is enough that one polytope in the target region is reachable""" # Continuous state space cont_state_space = pc.box2poly([[0., 1.], [0., 2.]]) # System dynamics (continuous state, discrete time): simple double integrator # but no reversing. h = 1.0 A = np.array([[1.0, h], [0., 1.0]]) B = np.array([[h**2 / 2.0], [h]]) E = None # Available control, no disturbances. Can brake or accelerate. U = pc.box2poly(np.array([[-1., 1.]])) W = None # Construct the LTI system describing the dynamics sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space) # Define atomic propositions for relevant regions of state space cont_props = dict() cont_props['target'] = pc.box2poly([[0., 1.], [0., 2.]]) # Compute the proposition preserving partition of the continuous state space # noinspection PyTypeChecker cont_partition = abstract.prop2part(cont_state_space, cont_props) # Abstraction disc_dynamics = abstract.discretize(cont_partition, sys_dyn, closed_loop=False, conservative=True, N=1, min_cell_volume=0.01, plotit=False, simu_type='bi', trans_length=1) # Setup a start point and a target point in a region that are problematic c_start_state = np.array([0.5, 0.0]) c_end_desired = np.array([1.0, 2.0]) # Find the discrete states of the start state and the target region d_start_state = abstract.find_discrete_state(c_start_state, disc_dynamics.ppp) d_end_state = abstract.find_discrete_state(c_end_desired, disc_dynamics.ppp) # Try to find a control policy u = abstract.find_controller.get_input(x0=c_start_state, ssys=sys_dyn, abstraction=disc_dynamics, start=d_start_state, end=d_end_state, ord=1, mid_weight=5) assert 0.5 <= u <= 1.0, "u was " + str(u) # Try to find a control policy in the other direction and ascertain # an error is thrown assert_raises(Exception, abstract.find_controller.get_input, x0=c_end_desired, ssys=sys_dyn, abstraction=disc_dynamics, start=d_end_state, end=d_start_state, ord=1, mid_weight=5)