Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import agent
import simulation
import motorPrimitive
import visual
import combine_motorPrimitives
# AGENT PARAMETERS ------------------------------------------------
size = 5
color = 'r'
# AGENT INITIALIZED --------------------------------------------
agent1 = agent.Agent(size,color)
X = combine_motorPrimitives.final_x
Y = combine_motorPrimitives.final_y
PHI = combine_motorPrimitives.MP1_phi
# FIGURE VISUALIZATION -----------------------------------------
## ANIMATION FIGURE
fig = plt.figure(1,figsize=(7,5))
ax = plt.axes(xlim=(-5,300), ylim=(0,300))
ax.set_title('Simulation')
patch = plt.Circle((combine_motorPrimitives.start_x,combine_motorPrimitives.start_y), agent1.size, fc = agent1.color)
ax.plot(X,Y,'lightsteelblue')
## XY, AND MOTOR PRIM IN FIGURE 2 --------------------------------
visual.mp_phi_plot(combine_motorPrimitives.MP1_alist,combine_motorPrimitives.MP1_func,combine_motorPrimitives.MP1_phi,
combine_motorPrimitives.MP2_alist,combine_motorPrimitives.MP2_func,combine_motorPrimitives.MP2_phi)
visual.xy_plot(X,Y,combine_motorPrimitives.summed_x,combine_motorPrimitives.summmed_y)
# INITIAL STATE OF THE PLOT ------------------------------------
def init():
ax.add_patch(patch)
return patch,
# TRANSFORMATION PER FRAME -------------------------------------
def animate(i):
x,y = patch.center # initial position of the agent
x = X[i]
y = Y[i]
patch.center = (x, y)
return patch,
# MATPLOTLIB SIMULATION FUNCTION THAT USES INIT() AND ANIMATE()
anim = animation.FuncAnimation(fig, animate,
init_func=init,
interval = 2,
frames=2000,
blit=True,
repeat = False)
plt.show()