def __init__(self, nb, buggy_nb, dist_per_tick=17.5 / 18): self.dist_per_tick = dist_per_tick # Distance travelled per click self.count = 0 # Encoder count self._get_message = GetMessage() # Callback (private) topic = "buggy" + str(buggy_nb) + "/encoder" + str( nb) # i.e. buggy0/encoder0 rospy.Subscriber(topic, Int64, self._get_message) # Subscribe to topic
class Gyroscope(object): def __init__(self, nb, buggy_nb, axis=0): self.get_message = GetMessage() self.axis = axis topic = "buggy" + str(buggy_nb) + "/gyroscope" + str(nb) rospy.Subscriber(topic, String, self.get_message, queue_size=1) def get_data(self): data = self.get_message.get_msg().data return data
def __init__(self, nb, buggy_nb, pos, angle, min_dist=10, action="None", eff_angle=0.17, col=colors.lime_green): self.col = col self.min_dist = min_dist self.action = action self.local_pos = pos # Position relative to centre of buggy (cm) self.global_pos = pos # Position of the sensor in the world frame (cm) self.local_angle = angle # Angle relative to the buggy (rad) self.global_angle = angle # Angle of the sensor in the world frame (rad) self.eff_angle = eff_angle # Effective angle of sonar (rad) self.data = 0 # Measured value of sensor (cm) self.get_message = GetMessage() topic = "buggy" + str(buggy_nb) + "/sonar" + str(nb) rospy.Subscriber(topic, Int32, self.get_message)
class Camera(object): def __init__(self, nb, buggy_nb): self.get_image = GetMessage() topic = "buggy" + str(buggy_nb) + "/camera" + str(nb) rospy.Subscriber(topic, CompressedImage, self.get_image, queue_size=1) def get_frame(self): frame = self.get_image.get_msg().data frame = np.fromstring(frame, np.uint8) frame = cv2.imdecode(frame, cv2.IMREAD_COLOR) frame = np.stack((frame[:, :, 2], frame[:, :, 1], frame[:, :, 0]), axis=2) return frame
from get_message import GetMessage from send_email import SendEmail from database import Database if __name__ == '__main__': # Define variables to connect to MySQL database user = '******' # Set username of MySQL server password = '' # Set password of MySQL server d = Database(user, password) n = int(input("Number of queries")) for query in range(n): email=input("Email address") series = input("TV Series").split(',') message = "\n" #Create an object for Database class #Connect to database and insert the data in the table. d.write(email,series) for i in series: #Create an object for GetMessage class which can determine the next episode date of the TV Series. m = GetMessage(i) #print(a.get_imdb_url()) message+="Tv series name: "+i+"\n" message+="Status: "+m.get_episode_date()+"\n" #print(message) message+="\n" #Send the result to user's email e = SendEmail(email,message) e.send()
def __init__(self, nb, buggy_nb, axis=0): self.get_message = GetMessage() self.axis = axis topic = "buggy" + str(buggy_nb) + "/gyroscope" + str(nb) rospy.Subscriber(topic, String, self.get_message, queue_size=1)
class Sonar(object): def __init__(self, nb, buggy_nb, pos, angle, min_dist=10, action="None", eff_angle=0.17, col=colors.lime_green): self.col = col self.min_dist = min_dist self.action = action self.local_pos = pos # Position relative to centre of buggy (cm) self.global_pos = pos # Position of the sensor in the world frame (cm) self.local_angle = angle # Angle relative to the buggy (rad) self.global_angle = angle # Angle of the sensor in the world frame (rad) self.eff_angle = eff_angle # Effective angle of sonar (rad) self.data = 0 # Measured value of sensor (cm) self.get_message = GetMessage() topic = "buggy" + str(buggy_nb) + "/sonar" + str(nb) rospy.Subscriber(topic, Int32, self.get_message) def update(self, buggy_pos, buggy_angle): self.global_pos = self._transform(buggy_pos, buggy_angle) self.global_angle = -(self.local_angle + buggy_angle) self.data = self.get_message.get_msg().data def draw(self, display, buggy_pos, buggy_angle, scale=1): pos = self._transform(buggy_pos, buggy_angle, scale=scale, flip=True) angle = self.global_angle pos = [int(n) for n in pos] pygame.draw.circle(display, self.col, pos, int(2 * scale)) # Draw sensor # NB: For low data values, drawing an arc is impossible if self.data > 5: data = self.data * scale # Scale sensor value with GUI rect = (pos[0] - data, pos[1] - data, 2 * data, 2 * data ) # Calculate rect of arc start_angle = -self.eff_angle - angle + math.pi / 2 # Depends of effective angle end_angle = self.eff_angle - angle + math.pi / 2 pygame.draw.arc(display, self.col, rect, start_angle, end_angle, 2) # Draw sensor arc def _transform(self, buggy_pos, buggy_angle, scale=1, flip=False): # Return position of sonar given buggy orientation and local sonar coordinates if flip: # Flip argument is for drawing sonar position flipped vertically flip = -1 else: flip = 1 buggy_x = buggy_pos[0] buggy_y = buggy_pos[1] local_x = float(self.local_pos[0]) local_y = float(self.local_pos[1]) angle = math.atan(local_x / local_y) if local_y < 0: angle += math.pi angle -= buggy_angle l = math.sqrt(local_x**2 + local_y**2) x = l * math.sin(angle) * scale + buggy_x y = flip * l * math.cos(angle) * scale + buggy_y return [x, y]
def __init__(self, nb, buggy_nb): self.get_image = GetMessage() topic = "buggy" + str(buggy_nb) + "/camera" + str(nb) rospy.Subscriber(topic, CompressedImage, self.get_image, queue_size=1)