Skip to content

Commit 0cad995

Browse files
authored
Add files via upload
1 parent 21f7d88 commit 0cad995

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import print_function
5+
def read_fences(file_path):
6+
"""Reads fence positions from a TSP file format and converts them to obstacles."""
7+
fences = []
8+
with open(file_path, 'r') as f:
9+
reading_nodes = False
10+
for line in f:
11+
if "NODE_COORD_SECTION" in line:
12+
reading_nodes = True
13+
elif "EOF" in line:
14+
break
15+
elif reading_nodes:
16+
_, x, y = line.split()
17+
fences.append([float(x), float(y)])
18+
return fences
19+
20+
class Config:
21+
def __init__(self, fences_file):
22+
self.max_speed = 1.0 # [m/s]
23+
self.min_speed = -0.5 # [m/s]
24+
self.max_yaw_rate = 40.0 * math.pi / 180.0 # [rad/s]
25+
self.max_accel = 0.2 # [m/ss]
26+
self.max_delta_yaw_rate = 40.0 * math.pi / 180.0 # [rad/ss]
27+
self.v_resolution = 0.01 # [m/s]
28+
self.yaw_rate_resolution = 0.1 * math.pi / 180.0 # [rad/s]
29+
self.dt = 0.1 # [s] Time tick for motion prediction
30+
self.predict_time = 3.0 # [s]
31+
self.to_goal_cost_gain = 0.15
32+
self.speed_cost_gain = 1.0
33+
self.obstacle_cost_gain = 1.0
34+
self.robot_stuck_flag_cons = 0.001 # constant to prevent robot stucked
35+
self.robot_type = RobotType.circle
36+
self.robot_radius = 1.0 # [m] for collision check
37+
self.robot_width = 0.5 # [m] for collision check
38+
self.robot_length = 1.2 # [m] for collision check
39+
40+
# Read the obstacles from the fences file
41+
self.ob = np.array(read_fences(fences_file))
42+
# Usage example
43+
FENCES_FILE = '/home/dell/ALNS/Fences.tsp'
44+
config = Config(FENCES_FILE)
45+
46+
print("Obstacle coordinates:")
47+
print(config.ob)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import print_function
5+
import numpy as np
6+
import math
7+
8+
class RobotType:
9+
circle = 1
10+
rectangle = 2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import print_function
5+
def dwa_control(x, config, goal, ob):
6+
dw = calc_dynamic_window(x, config)
7+
u, trajectory = calc_control_and_trajectory(x, dw, config, goal, ob)
8+
return u, trajectory
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import time
5+
import math
6+
import sys
7+
import pathlib
8+
import threading
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
import argparse
12+
import random
13+
from enum import Enum
14+
from dronekit import connect, VehicleMode, LocationGlobalRelative
15+
from pymavlink import mavutil # Needed for command message definitions
16+
def plot_robot(x, y, yaw, config):
17+
if config.robot_type == RobotType.rectangle:
18+
outline = np.array([[-config.robot_length / 2, config.robot_length / 2,
19+
(config.robot_length / 2), -config.robot_length / 2,
20+
-config.robot_length / 2],
21+
[config.robot_width / 2, config.robot_width / 2,
22+
- config.robot_width / 2, -config.robot_width / 2,
23+
config.robot_width / 2]])
24+
Rot1 = np.array([[math.cos(yaw), math.sin(yaw)],
25+
[-math.sin(yaw), math.cos(yaw)]])
26+
outline = (outline.T.dot(Rot1)).T
27+
outline[0, :] += x
28+
outline[1, :] += y
29+
plt.plot(np.array(outline[0, :]).flatten(),
30+
np.array(outline[1, :]).flatten(), "-k")
31+
elif config.robot_type == RobotType.circle:
32+
circle = plt.Circle((x, y), config.robot_radius, color="b")
33+
plt.gcf().gca().add_artist(circle)
34+
out_x, out_y = (np.array([x, y]) +
35+
np.array([np.cos(yaw), np.sin(yaw)]) * config.robot_radius)
36+
plt.plot([x, out_x], [y, out_y], "-k")

0 commit comments

Comments
 (0)