Exemplo n.º 1
0
 def get_final_location(message):
     try:
         lat, lon = message.location.latitude, message.location.longitude
         conn = sqlite3.connect('users.db')
         cursor = conn.cursor()
         query = 'SELECT Home_lat, Home_long FROM tasks WHERE Courier=? AND Is_completed="FALSE"'
         location = cursor.execute(query, [message.from_user.id]).fetchone()
         conn.close()
         if functions.calculate_distance(lat, lon, location[0],
                                         location[1]) < 0.05:
             conn = sqlite3.connect('users.db')
             cursor = conn.cursor()
             query = 'SELECT Owner_telegram_id FROM tasks WHERE Courier=? AND Is_completed="FALSE"'
             customer_id = cursor.execute(
                 query, [message.from_user.id]).fetchone()[0]
             conn.close()
             markup = types.InlineKeyboardMarkup()
             data = str(message.chat.id) + '-0'
             btn1 = types.InlineKeyboardButton(
                 text='Подтвердить\u2705',
                 callback_data='{0}-COMPLETE_ORDER'.format(data))
             markup.add(btn1)
             bot.send_message(
                 customer_id,
                 'Ваш заказ доставлен, подтвердите получение товаров.',
                 reply_markup=markup)
         else:
             bot.send_message(message.chat.id,
                              'Как-то ты слишком далеко, подойди поближе')
             bot.register_next_step_handler(message, get_final_location)
     except Exception as e:
         print(e)
         bot.send_message(message.chat.id, phrases.wrong_location)
         bot.register_next_step_handler(message, enter_point)
Exemplo n.º 2
0
def get_enlongated_line(coords_start):
    new_coords = []
    while True:
        changes = 0
        if not new_coords:
            coords = coords_start
        new_coords = []
        for i in range(len(coords) - 2):
            point_a = coords[i]
            point_b = coords[i + 1]
            distance = calculate_distance(point_a[0], point_a[1], point_b[0], point_b[1])
            new_coords.append(point_a)
            if distance > 10:
                new_coords.append((((point_a[0] + point_b[0]) / 2), ((point_a[1] + point_b[1]) / 2)))
                changes += 1

            if i == len(coords) - 3:
                new_coords.append(point_b)

        coords = new_coords
        if changes == 0:
            break
    return coords
Exemplo n.º 3
0
######################## Begin Navigation loop #######################
#Establishing first location after separation of parachute
while True:
    my_gps.update(chr(my_gps_uart.readchar()))
    if my_gps.latitude[0] != 0:
        start_lat = functions.convert_latitude(my_gps.latitude)
        start_long = functions.convert_longitude(my_gps.longitude)
        start_point = (start_lat, start_long)
        pyb.LED(3).on()
        pyb.delay(2000)
        pyb.LED(3).off()
        break

#Sending the location of the rover this marks the navigation process
#xbee.write('\nI will begin navigation at this location: {}'.format(past_point))
dist_from_goal = functions.calculate_distance(finish_point, start_point)
degree_to_turn = functions.bearing_difference(finish_point, landing_point,start_point)
functions.angle_to_motor_turn(wheel_separation, wheel_radius, gain, degree_to_turn[0], degree_to_turn[1])
past_point = start_point
pyb.LED(3).on()
pyb.delay(2000)
pyb.LED(3).off()

#Start Movement
while True:
    #This loop relies on checking for its location and replacing the initial_point with the most recently recorded point and determining bearing, distance, corrections etc..'''
    initial_point = past_point
    functions.move_forward(100)
    pyb.LED(3).on()
    pyb.delay(2000)
    pyb.LED(3).off()
Exemplo n.º 4
0
xbee.write('Parachute burned successfully....Aquiring Location')
with open('/sd/log.txt', 'a') as log:
    log.write('Parachute successfully burned\n')

############ Establish Landing / Aquire Bearing / Correct course ########

# Establish Landing Point
xbee.write('Aquiring Location...')
landing_point = int(functions.get_location)
xbee.write('Location aquired\n')
xbee.write('Landing point: {}\n'.format(landing_point))
with open('/sd/log.txt', 'a') as log:
    log.write('{}\n'.format(landing_point))

# Calculate Distance to goal
dist_from_goal = functions.calculate_distance(finish_point, landing_point)

xbee.write('\nDistance from Goal: {}'.format(dist_from_goal))

with open('/sd/log.txt', 'a') as log:
    log.write('Distance from goal: {}\n'.format(dist_from_goal))

functions.move_forward(80)
cruise_speed = 80
functions.cruise_control(10000, cruise_speed)  # Duration 10s, 80% duty cycle
# Establish an arbitrary point after landing point to aquire bearing
bearing_point = int(functions.get_location())
with open('/sd/log.txt', 'a') as log:
    log.write('Point to establish bearing aquired: {}\n'.format(bearing_point))

# Now that 3 points have been established we can establish bearing and correct course
Exemplo n.º 5
0
                df.latitude = df.latitude.astype(float)
                df.longitude = df.longitude.astype(float)

df['magnitude'] = df['magnitude'].astype('float')
df['latitude'] = df['latitude'].astype('float')
df['longitude'] = df['longitude'].astype('float')
df['depth'] = df['depth'].astype('int')
df['location'] = df['location'].astype('str')
df['day'] = pd.to_datetime(df['day'])
df['time'] = pd.to_datetime(df['time']).dt.time
df_lat = df.latitude.tolist()
df_long = df.longitude.tolist()

area = []
for i in range(len(df_lat)):
    distance_between_towns = fc.calculate_distance(df_lat[i], locate[0],
                                                   df_long[i], locate[1])
    area.append(fc.calculate_area(distance_between_towns))

areatosearch = fc.calculate_area(int(radius_to_search))
Area = pd.Series(area)
df['Area'] = Area.values

df = df[(df['location'].str.contains(town, case=False)) |
        (df['Area'] <= areatosearch)]
df = df[((df['day'] <= endday) & (df['day'] >= startday))]
df = df.sort_values(by='day', ascending=False)

lon_list = df.longitude.tolist()
lat_list = df.latitude.tolist()
locat_list = df.location.tolist()
df['day'] = df['day'].dt.date  #dropping the time bit (00:00:00)