def move(self, goal_dist, callback=None, erase=True): """ same thing as moveTo """ if erase: self.goal_dist = [] self.goal_dist.append(Distance(goal_dist, callback)) motion.move(goal_dist, self.private_move_callback)
def mainloop(j, sx, ex, srange, erange, ups, ls): k2 = translate(j, sx, ex, srange, erange) y2 = 150 # put your y2 equation here te3, te4 = move(k2, y2) alpha = translate(te3, 0, 180, ups.sp, ups.ep) beta = translate(te4 - 90, 0, 180, ls.sp, ls.ep) return alpha, beta
def callback(data): motion.move(data.data)
def _move(self): delta_x, delta_y = motion.move(self.speed, self.angle) self.center_x += delta_x self.center_y += delta_y
import socket from motion import click, move # UDP_IP = "127.0.0.1" UDP_IP = "0.0.0.0" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, _ = sock.recvfrom(16) print("received message:", data) message = data.decode() tab = message.split(' ') # x, y, cl (int, int 0/1) x, y, cl = int(tab[0]), int(tab[1]), int(tab[2]) move(x, y) if cl == 1: click()
import motion import socket CONNECTION_LIST = [] # list of socket clients REVC_BUFFER = 4096 PORT = 8080 HOST = '192.168.1.108' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind(HOST, PORT) except socket.error as msg: print "Bind failed. Error code: " + str(msg[0] + "Message" + msg[1]) exit(1) s.listen(5) print "socket binds successfully, and is listening now." conn, addr = s.accept() print "Connected with " + addr[0] + str(addr[1]) while True: s.close() motion.move("fr")
# outputs.remove(s) # else: # s.send(next_msg) for s in exceptional: inputs.remove(s) if s in outputs: outputs.remove(s) s.close() del message_queues[s] rightTurn = [0.0, 0.0, 0.40] leftTurn = [0.0, 0.0, -0.40] walkForward = [0.8, 0.0, 0.0] standing = False if (message == "StandIsGo" and not standing): posture.goToPosture("StandInit", 1.0) standing = True elif (message == "WalkIsGo"): motion.move(walkForward[0], walkForward[1], walkForward[2]) elif (message == "WalkIsStop"): motion.move(0, 0, 0.0) elif (message == "TurnRight"): print(message) motion.post.moveTo(rightTurn[0], rightTurn[1], rightTurn[2]) elif (message == "TurnLeft"): print(message) motion.post.moveTo(leftTurn[0], leftTurn[1], leftTurn[2]) elif (message == "Sit"): posture.goToPosture("Sit", 1.0)
def simulate_learning(neurons, receptors, nrns_sd, rctrs_sd, arena): """ Run simulation for 40 seconds based on network topology encoded in individual. @param individual: Binary string encoding network topology. @param arena: The arena object in which the simulation is carried out. @param n_step: Number of steps the simulation is divided in. @param t_step: Number of milliseconds in each step. @param reset: bool triggering the reset of the nest kernel. """ global simtime simdata = create_empty_data_lists() if data['init'] == 'random': simdata['x_init'], simdata['y_init'], theta_init = \ select_random_pose(arena) x_cur = simdata['x_init'] y_cur = simdata['y_init'] theta_cur = theta_init err_l, err_r = 0, 0 simdata['rctr_nrn_trace'].append(np.zeros((18, 10))) simdata['nrn_nrn_trace'].append(np.zeros((10, 10))) motor_spks = nrns_sd[6:] for t in range(n_step): ev.update_refratory_perioud() simdata['traj'].append((x_cur, y_cur)) px = network.set_receptors_firing_rate(x_cur, y_cur, theta_cur, err_l, err_r) simdata['pixel_values'].append(px) # Run simulation for time-step nest.Simulate(t_step) simtime += t_step motor_firing_rates = network.get_motor_neurons_firing_rates(motor_spks) v_l_act, v_r_act, v_t, w_t, err_l, err_r, col, v_l_des, v_r_des = \ motion.update_wheel_speeds(x_cur, y_cur, theta_cur, motor_firing_rates) # Save dsired and actual speeds simdata['speed_log'].append((v_l_act, v_r_act)) simdata['desired_speed_log'].append((v_l_des, v_r_des)) # Save motor neurons firing rates simdata['motor_fr'].append(motor_firing_rates) # Save linear and angualr velocities simdata['linear_velocity_log'].append(v_t) simdata['angular_velocity_log'].append(w_t) # Move robot according to the read-out speeds from motor neurons x_cur, y_cur, theta_cur = motion.move(x_cur, y_cur, theta_cur, v_t, w_t) nrns_st, rctrs_st = learning.get_spike_times(nrns_sd, rctrs_sd) rec_nrn_tags, nrn_nrn_tags, rctr_t, nrn_t, pt = \ learning.get_eligibility_trace(nrns_st, rctrs_st, simtime, simdata['rctr_nrn_trace'][t], simdata['nrn_nrn_trace'][t]) print simtime simdata['rctr_nrn_trace'].append(rec_nrn_tags) simdata['nrn_nrn_trace'].append(nrn_nrn_tags) # Stop simulation if collision occurs if col: simdata['speed_log'].extend((0, 0) for k in range(t, 400)) break simdata['fitness'] = ev.get_fitness_value(simdata['speed_log']) return simdata, rctr_t, nrn_t, pt, col
def simulate_evolution(individual, arena, n_step, t_step, reset=True): """ Run simulation for 40 seconds based on network topology encoded in individual. @param individual: Binary string encoding network topology. @param arena: The arena object in which the simulation is carried out. @param n_step: Number of steps the simulation is divided in. @param t_step: Number of milliseconds in each step. @param reset: bool triggering the reset of the nest kernel. """ # Reset nest kernel just in case it was not reset & adjust # resolution. nest.ResetKernel() nest.SetKernelStatus({'resolution': 1.0, 'local_num_threads': 4}) nest.set_verbosity('M_ERROR') if data['init'] == 'random': x, y, theta = select_random_pose(arena) simdata = create_empty_data_lists() simdata['x_init'] = x_init simdata['y_init'] = y_init simdata['theta_init'] = theta_init motor_spks = network.create_evolutionary_network(individual, data['model']) x_cur = x_init y_cur = y_init theta_cur = theta_init err_l, err_r = 0, 0 for t in range(n_step): # Save current position in trajectory list simdata['traj'].append((x_cur, y_cur)) # Add nioise to network.update_refratory_perioud(data['model']) # Set receptors' firing probability px = network.set_receptors_firing_rate(x_cur, y_cur, theta_cur, err_l, err_r, arena) simdata['pixel_values'].append(px) # Run simulation for 100 ms nest.Simulate(t_step) motor_firing_rates = network.get_motor_neurons_firing_rates(motor_spks) # Get desired and actual speeds col, speed_dict = motion.update_wheel_speeds(x_cur, y_cur, theta_cur, motor_firing_rates, t_step, arena) # Stop simulation if collision occurs if col: simdata['speed_log'].extend((0, 0) for k in range(t, 400)) break # Save simulation data simdata['speed_log'].append((speed_dict['actual_left'], speed_dict['actual_right'])) simdata['desired_speed_log'].append((speed_dict['desired_left'], speed_dict['desired_right'])) simdata['motor_fr'].append(motor_firing_rates) simdata['linear_velocity_log'].append(speed_dict['linear']) simdata['angular_velocity_log'].append(speed_dict['angular']) # Move robot according to the read-out speeds from motor neurons x_cur, y_cur, theta_cur = motion.move(x_cur, y_cur, theta_cur, speed_dict['linear'], speed_dict['angular'], t_step/1000.) # Calculate individual's fitness value simdata['fitness'] = ev.get_fitness_value(simdata['speed_log']) # Get average number of spikes per second for each neuron simdata['average_spikes'] = network.get_average_spikes_per_second() # Get Voltmeter data simdata['voltmeter_data'] = network.get_voltmeter_data() if reset: nest.ResetKernel() return simdata