def run_sim(): # create the model dae = carousel_dae.makeDae() # compute the steady state steady_state, _ = getSteadyState(dae, 100, 20) # create the sim dt = 0.01 sim = rawe.sim.Sim(dae, dt) communicator = Communicator() joy = Joy() # set the initial state from steady_state sim_x = {} for name in dae.xNames(): sim_x[name] = steady_state[name] sim_u = {} for name in dae.uNames(): sim_u[name] = steady_state[name] sim_p = {} for name in dae.pNames(): sim_p[name] = steady_state[name] # set up the sim timer timer = rawe.sim.Timer(dt) timer.start() # loop through and simulate # if there's an error close the communicator and throw exception sim_time = 0.0 try: while True: # sleep for dt timer.sleep() print "running: "+str(sim_time) # send message to visualizer/plotter communicator.send_kite(sim_x, sim_u, sim_p, sim.getOutputs(sim_x, sim_u, sim_p)) # try to take a simulation step of dt try: js = joy.getAll() rudder = js['axes'][0]*numpy.radians(5) aileron = js['axes'][3]*numpy.radians(5) elevator = js['axes'][4]*numpy.radians(5) #print "rudder: ",rudder #print "aileron: ",aileron #print "elevator: ",elevator sim_x['rudder'] = rudder sim_x['aileron'] = aileron sim_x['elevator'] = elevator sim_x = sim.step(sim_x, sim_u, sim_p) except RuntimeError: # problem simulating, close the communicator communicator.close() raise Exception('OH NOES, IDAS CHOKED') sim_time += dt except KeyboardInterrupt: print "closing..." communicator.close()
ocp.lookup('endTime')) return ocp if __name__ == '__main__': print "reading config..." # from carousel_conf import conf #from highwind_carousel_conf import conf from rawe.models.betty_conf import makeConf nk = 100 * numLoops # nk = 70 print "creating model..." conf = makeConf() dae = carousel_dae.makeDae(conf) dae.addP('endTime') conf['minAltitude'] = 0.5 print "setting up ocp..." nicp = 1 deg = 4 collPoly = 'RADAU' #collPoly='LEGENDRE' ocp = setupOcp(dae, conf, nk, nicp, deg, collPoly) # spawn telemetry thread callback = rawe.telemetry.startTelemetry( ocp, callbacks=[(rawe.telemetry.trajectoryCallback(toProto, Trajectory,
def get_steady_state_guess(): ddelta = nTurns*2*pi/(ocp._guess.lookup('endTime')) from rawekite.carouselSteadyState import getSteadyState conf_ss = makeConf() steadyState,_ = getSteadyState(carousel_dae.makeDae(conf_ss), None, ddelta, lineRadiusGuess, {}) return steadyState
# boundary conditions ocp.bound('sin_delta', (0,0), timestep=0, quiet=True) ocp.bound('cos_delta', (0.5,1.5), timestep=0, quiet=True) ocp.bound('cos_delta', (0.5,1.5), timestep=-1, quiet=True) return ocp if __name__=='__main__': from rawe.models.betty_conf import makeConf conf = makeConf() conf['runHomotopy'] = True conf['minAltitude'] = 0.5 nk = 75 dae = carousel_dae.makeDae(conf) dae.addP('endTime') print "setting up ocp..." ocp = setupOcp(dae,conf,nk) lineRadiusGuess = 4.0 nTurns = 1 # trajectory for homotopy def get_steady_state_guess(): ddelta = nTurns*2*pi/(ocp._guess.lookup('endTime')) from rawekite.carouselSteadyState import getSteadyState conf_ss = makeConf() steadyState,_ = getSteadyState(carousel_dae.makeDae(conf_ss), None, ddelta, lineRadiusGuess, {}) return steadyState
def get_steady_state_guess(): from rawekite.carouselSteadyState import getSteadyState conf_ss = makeConf() steadyState,_ = getSteadyState(carousel_dae.makeDae(conf_ss), None, ddelta0, lineRadiusGuess, {}) return steadyState