Skip to content

optimum_trajectory_regenerate #1

Description

@harunkurtdev

Hello, while looking at your code, I am not sure if there is an error in the operation, but you can look at it here.

image

I get an error like this when we use agents in this way.

Traceback (most recent call last):
  File "/home/x/swarm.py", line 216, in <module>
    safe_trajectory = cc.main()
  File "/home/x/swarm.py", line 51, in main
    ax1 , ay1 = self.optimum_trajectory_regenerate(trajUAV=trajUAVPre, xc=self.xc[i], yc=self.yc[i], xt=self.xt[i], yt=self.yt[i], N=self.N, h=self.h, r=self.r_col, ID=i,K=K)
  File "/home/x/swarm.py", line 179, in optimum_trajectory_regenerate
    var3 = (var1.T-var2.T).T@c.T
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

I use that your code like this,

x_init = [0, 1, 2]   # Example initial x positions of agents
y_init = [0, 1, 2]   # Example initial y positions of agents
x_final = [3, 4, 5]  # Example final x positions of agents
y_final = [-3, -4, -5]  # Example final y positions of agents
N = 10               # Number of waypoints
numUAV = 3           # Number of agents
h = 0.1              # Discrete time step
r_col = 0.5          # Collision radius

# Instantiate the convex_collision object
cc = convex_collison(x_init, y_init, x_final, y_final, N, numUAV, h, r_col)

# Compute the safe trajectory for the swarm
safe_trajectory = cc.main()

# Access the safe trajectory from the returned value
print("Safe Trajectory:", safe_trajectory)


# Extract x and y coordinates for each agent from the safe trajectory
agent_paths = safe_trajectory

# Plot the paths of each agent
for agent_id, path in enumerate(agent_paths):
    x_path, y_path = path
    plt.plot(x_path, y_path, label=f"Agent {agent_id+1}")

# Add initial positions
for agent_id, (x_init_agent, y_init_agent) in enumerate(zip(x_init, y_init)):
    plt.scatter(x_init_agent, y_init_agent, color='red', marker='o', label=f"Initial position of Agent {agent_id+1}")

# Add final positions
for agent_id, (x_final_agent, y_final_agent) in enumerate(zip(x_final, y_final)):
    plt.scatter(x_final_agent, y_final_agent, color='green', marker='x', label=f"Final position of Agent {agent_id+1}")

# Set plot title and labels
plt.title("Safe Trajectory of Swarm Agents")
plt.xlabel("X Position")
plt.ylabel("Y Position")
plt.legend()
plt.grid(True)

# Show plot
plt.show()

can you explain why is it getting error ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions