def main(): try: print('[main] Initializing model') #model = model(HYDROPHONE_POS) print('[main] Initializing threads') #start profiler #pf = sonar_profiler() #start processor s_p = sonar_processor.sonar_processor() print('[main] Starting DSM') #begin interfacing with DSM client = pydsm.Client(CLIENT_SERV, CLIENT_ID, True) print('[main] Starting threads') #pf.start() s_p.start() #TODO probably don't need to reg remote buffers, but if need to, it is here #for i in range(len(bufNames)): # client.registerRemoteBuffer(bufNames[i], bufIps[i], int(bufIds[i])) for i in range(100): s_p.callback('GO') print(str(s_p.found_locs)) time.sleep(0.5) pc.join() except KeyboardInterrupt: print('\n[main] Ctrl+c received. Ending program') #send end_callbacks to all threads s_p.callback('END') sys.exit(1) print('[main] Ending program')
def main(): client = pydsm.Client(42, settings.CLIENT_ID, True) client.registerLocalBuffer("control", sizeof(ControlInput), False) client.registerLocalBuffer("sensorreset", sizeof(SensorReset), False) client.registerLocalBuffer("droppers", sizeof(DropperInput), False) # client.registerLocalBuffer("status", sizeof(Status), False) time.sleep(0.5) control_input = set_control(client, 0, 0, 0) client.setLocalBufferContents("sensorreset", pack(sensorReset)) droppers = set_droppers(client, False, False) # client.setLocalBufferContents("status", pack(status)) print("Created local buffers: control, sensorreset, status") register_remote_buffers(client, settings.remote_buffers) print("Registered remote buffers") state = KilledState() while True: try: # get new data data_in = update_remote_buffers(client, settings.remote_buffers) # update conditions list(map(lambda x: x.prepare(), conditions.values())) list( map(lambda x: x((control_input, data_in)), conditions.values())) # advance one state next_state = state((control_input, data_in, conditions)) # set outputs control_input = set_control(client, state.heading(), state.depth(), state.velocity()) strState = str(state) if "new_frame" not in strState: print(state) state = next_state # sleep a bit time.sleep(0.01) except KeyboardInterrupt: print("Caught control-C, exiting") break
SERVERID = MOTOR_SERVER_ID CLIENTID = 100 outputs = Outputs() for i in range(8): outputs.motors[i] = i * 10 health = Health() health.saturated = 0x00 health.direction = 0x00 kill = Kill() kill.isKilled = True client = pydsm.Client(SERVERID, 100, True) client.registerLocalBuffer("outputs", sizeof(Outputs), False) client.registerLocalBuffer("health", sizeof(Health), False) client.registerLocalBuffer("kill", sizeof(Kill), False) time.sleep(0.1) if (client.setLocalBufferContents("outputs", Pack(outputs))): print("set outputs") if (client.setLocalBufferContents("health", Pack(health))): print("set health") if (client.setLocalBufferContents("kill", Pack(kill))): print("set kill") try: while True:
sensorReset.pos[ZAXIS] = 0 sensorReset.reset = False for i in range(3): angular.pos[i] = 0 angular.vel[i] = 0 angular.acc[i] = 0 linear.pos[i] = 0 linear.vel[i] = 0 linear.acc[i] = 0 angular.pos[0] = 1 angular.pos[3] = 0 kill.isKilled = False client = pydsm.Client(SERVER_ID, CLIENT_ID, True) client.registerLocalBuffer("control", sizeof(ControlInput), False) client.registerLocalBuffer(MASTER_SENSOR_RESET, sizeof(SensorReset), False) time.sleep(0.5) client.setLocalBufferContents("control", Pack(controlInput)) client.setLocalBufferContents(MASTER_SENSOR_RESET, Pack(sensorReset)) print("Created local buffers: control, sensorreset") client.registerRemoteBuffer("angular", SENSOR_IP, SENSOR_ID) client.registerRemoteBuffer("linear", SENSOR_IP, SENSOR_ID) client.registerRemoteBuffer("kill", NAVIGATION_IP, NAVIGATION_ID) time.sleep(0.1) print("Registered remote buffers: angular,linear,kill") ABOVE = True
linearCommand.force[xaxis] = 0 linearCommand.force[yaxis] = 0 linearCommand.force[zaxis] = 0 linearCommand.torque[xaxis] = 0 linearCommand.torque[yaxis] = 0 linearCommand.torque[zaxis] = 0 angularCommand = PhysicalOutput() angularCommand.force[xaxis] = 0 angularCommand.force[yaxis] = 0 angularCommand.force[zaxis] = 0 angularCommand.torque[xaxis] = 0 angularCommand.torque[yaxis] = 0 angularCommand.torque[zaxis] = 0 client = pydsm.Client(SERVERID, CLIENTID, True) client.registerLocalBuffer(LINEAR_NAME, sizeof(linearCommand), False) client.registerLocalBuffer(ANGULAR_NAME, sizeof(angularCommand), False) time.sleep(0.1) client.setLocalBufferContents(LINEAR_NAME, Pack(linearCommand)) client.setLocalBufferContents(ANGULAR_NAME, Pack(angularCommand)) def update(): client.setLocalBufferContents(LINEAR_NAME, Pack(linearCommand)) client.setLocalBufferContents(ANGULAR_NAME, Pack(angularCommand)) def lx(force):
f = open(filename) print ('reading file') global data data = imp.load_source('data', '', f) f.close() def pp(s): print ('printing data:') for field_name, field_type in s._fields_: print(field_name, getattr(s, field_name)) if __name__ == "__main__": print("Initializing Client") sensorClient = pydsm.Client(SENSOR_SERVER_ID, 71, True) motorClient = pydsm.Client(MOTOR_SERVER_ID, 72, True) forwardVisionClient = pydsm.Client(FORWARD_VISION_SERVER_ID, 73, True) downwardVisionClient = pydsm.Client(DOWNWARD_VISION_SERVER_ID, 74, True) sonarClient = pydsm.Client(SONAR_SERVER_ID, 75, True) print("Creating Local Buffers") sensorClient.registerLocalBuffer(SENSORS_LINEAR, sizeof(Linear), False) sensorClient.registerLocalBuffer(SENSORS_ANGULAR, sizeof(Angular), False) forwardVisionClient.registerLocalBuffer(TARGET_LOCATION, sizeof(LocationArray), False) downwardVisionClient.registerLocalBuffer(TARGET_LOCATION_AND_ROTATION, sizeof(LocationArray), False) sonarClient.registerLocalBuffer(TARGET_LOCATION, sizeof(LocationArray), False) motorClient.registerLocalBuffer(MOTOR_KILL, sizeof(Kill), False) time.sleep(1) linear = Linear() angular = Angular()
import pydsm import time from Sensor import * from Master import * from Vision import * if __name__ == "__main__": #register or remote need time.sleep(0.1) print("Deadreckoning through the gate") time.sleep(23) print("Through the gate") print("establishing the client") #listen to the sensor, motor and vision client = pydsm.Client(MASTER_SERVER_ID, 66, True) client.registerLocalBuffer(MASTER_CONTROL, sizeof(ControlInput), False) client.registerLocalBuffer(MASTER_GOALS, sizeof(Goals), False) client.registerLocalBuffer(MASTER_SENSOR_RESET, sizeof(SensorReset), False) time.sleep(1) control_input = ControlInput() goals = Goals() sensor_reset = SensorReset() client.setLocalBufferContents(MASTER_CONTROL, Pack(control_input)) client.setLocalBufferContents(MASTER_GOALS, Pack(goals)) client.setLocalBufferContents(MASTER_SENSOR_RESET, Pack(sensor_reset)) print("eastablishing the sensor, motor and vision") #tells dsm what you are listening or publishing client.registerRemoteBuffer(SENSORS_LINEAR, sizeof(Linear), False)
import argparse import ipaddress def validateIP(addr): try: ipaddress.ip_address(addr) except ValueError: return False return True if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('serverID', type=int) parser.add_argument('clientID', type=int) args = parser.parse_args() client = pydsm.Client(args.serverID, args.clientID, True) try: while (1): tokens = input("> ").split() if (tokens[0] == "kill" or tokens[0] == "exit"): print("exiting") break elif (tokens[0] == "regl" and len(tokens) == 3): if client.registerLocalBuffer(tokens[1], int(tokens[2]), False): print("Registered new local buffer") else: print("Invalid operands") elif (tokens[0] == "reglo" and len(tokens) == 3): if client.registerLocalBuffer(tokens[1], int(tokens[2]), True): print("Registered new local only buffer") else:
from Vision import * from Serialization import * #var for whether or not this run of the program is a test isReal = True if len(sys.argv) > 1: isReal = False #initialize log log = logger.LogWriter("downward") log.write("Beginning downward detection") #initialize buffer if isReal: client = pydsm.Client(DOWNWARD_VISION_SERVER_ID, 60, True) client.registerLocalBuffer(TARGET_LOCATION_AND_ROTATION, sizeof(LocationAndRotation), False) loc = LocationAndRotation() #initialize capture device print("Initializing camera") if isReal: camera = picamera.PiCamera() camera.resolution = (1920, 1080) camera.start_preview() time.sleep(1) # capture frames sequentially while True: if isReal: #Create a memory stream so photos doesn't need to be saved in a file
return ",".join(var_names) def create_string(key): active, obj = get_buffer(key) values = map(lambda x: "obj." + x[1], contents(key)) values = map(eval, values) values = map(float, values) values = map(lambda x: round(x, 4), values) values = map(str, values) values = list(values) values.append(str(int(active))) return ",".join(values) client = pydsm.Client(254, 193, True) def main(args): if len(args) > 1: log_dirname = args[1] else: log_dirname = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") log_dir = os.path.join(os.path.expanduser("~/robosub_logs"), log_dirname) os.makedirs(log_dir) log_filename = os.path.join(log_dir, "robosub.log") print("logging to file: ", log_filename) logger = logging.getLogger('logger') logger.setLevel(logging.INFO) handler = RotatingFileHandler(log_filename,