def publishBuffer(self): rospy.loginfo("Publishing buffer dishes...") loop_rate = rospy.Rate(self.loop_rate) for current_dish in range(self.buffer_size): # Initialize a new dish state d = dish_state() # For each channel in the dish state for channel in range(60): d.samples[channel] = 0.0 # print 'Channel', channel, ':' # If there are no recorded neurons on this channel, then the voltage is 0.0 # Otherwise, get the weighted average of the volts of the neurons on this channel if self.channels[channel] != None: for neuron in self.channels[channel].neurons: weight = neuron.weight / self.channels[channel].total_weight weighted = self.M[neuron.data][current_dish] * weight d.samples[channel] += weighted # print ' Neuron: ', neuron.data, 'Weight:', weight, 'State:', M[neuron.data][current_dish] # print ' Weighted State: ', weighted, 'Total:', d.samples[channel] # If we are publishing to burst_calc, then publish the dish_state now # Otherwise, do nothing with it if self.do_burst_calc == True: self.dish_pub_burst.publish(d) loop_rate.sleep()
def publish(self): rospy.loginfo("Publishing dishes...") loop_rate = rospy.Rate(self.loop_rate) current_dish = self.buffer_size while current_dish < len(self.M[self.recorded_neurons[0]]) and not rospy.is_shutdown(): # Initialize a new dish state d = dish_state() # For each channel in the dish state for channel in range(60): d.samples[channel] = 0.0 # print 'Channel', channel, ':' # If there are no recorded neurons on this channel, then the voltage is 0.0 # Otherwise, get the weighted average of the volts of the neurons on this channel if self.channels[channel] != None: for neuron in self.channels[channel].neurons: weight = neuron.weight / self.channels[channel].total_weight weighted = self.M[neuron.data][current_dish] * weight d.samples[channel] += weighted # print ' Neuron: ', neuron.data, 'Weight:', weight, 'State:', M[neuron.data][current_dish] # print ' Weighted State: ', weighted, 'Total:', d.samples[channel] # Add the time stamp d.header.stamp = rospy.Time.now() - self.offset # Publish the dish state if self.do_volt_distr == True: self.dish_pub_volt.publish(d) if self.do_burst_calc == True: self.dish_pub_burst.publish(d) self.dish_pub_viz.publish(d) # Sleep and move on to the next dish current_dish += 1 loop_rate.sleep() # Publish a final dish to let the nodes know to finish up end = dish_state() end.last_dish = True if self.do_volt_distr == True: self.dish_pub_volt.publish(end) if self.do_burst_calc == True: self.dish_pub_burst.publish(end) rospy.loginfo("Publishing finished")