Permalink
Cannot retrieve contributors at this time
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?
motor-primitives-in-steering-simulation/motorPrimitive.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (63 sloc)
2.84 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import animation | |
import templates | |
import agent | |
import simulation | |
class MotorPrimitive: | |
"This is the Motor primitive class. A motor primitive is an object that specifies the shape of an agent's trajectory for a specific time duration." | |
function = '' | |
amplitude = 0 | |
timeLength = 100 # 100 | |
timeStep = 0.1 # 0.1 | |
start_x,start_y,start_phi = 0,0,0 #starting position and starting angle | |
velocity = 1 | |
gain = 1 | |
# INITIALIZE MOTOR PRIMITIVE'S TIME-LENGTH,TIME-STEP, FUNCTION, AMPLITUDE | |
def __init__(self, timeLength, timeStep, function, amplitude,velocity, gain): | |
self.timeLength = timeLength | |
self.timeStep = timeStep | |
self.function = function | |
self.amplitude = amplitude | |
self.x=[] | |
self.y=[] | |
self.phi=[] | |
self.velocity = velocity | |
self.gain = gain | |
# INITIALIZE PARAMETER VALUES FOR MOTOR PRIMITIVE FUNCTION | |
def init_func(self,**var): | |
# parameters for function | |
self.mu = var.get('mu', None) | |
self.sigma = var.get('sigma', None) | |
self.shift = var.get('shift', None) | |
self.slope = var.get('slope', None) | |
self.y_int = var.get('y_int', None) | |
t = np.arange(0,self.timeLength+self.timeStep, self.timeStep) | |
if self.function == 'gaussian': | |
f = lambda t, g: templates.gaussian(t,self.mu,self.sigma,self.amplitude) | |
alist = np.arange(0,len(t)/10,1) #change this to accomodate other t_totals | |
gauss = templates.gaussian(alist, self.mu,self.sigma,self.amplitude) | |
return(f,t,alist,gauss) | |
elif self.function == 'sigmoid': | |
f = lambda t, s: templates.sigmoid(t,self.shift,self.amplitude,self.slope) | |
alist = np.arange(0,len(t)/10,1) #change this to accomodate other t_totals | |
sigmoid = templates.sigmoid(alist, self.shift,self.amplitude,self.slope) | |
return(f,t,alist,sigmoid) | |
elif self.function == 'straight': | |
f = lambda t, s: templates.straight(t,self.slope,self.y_int) | |
alist = np.arange(0,len(t)/10,1) #change this to accomodate other t_totals | |
straight = templates.straight(alist,self.slope,self.y_int) | |
return(f,t,alist,straight) | |
# PRINT ALL MOTOR PRIMITIVE ATTRIBUTES | |
def MP_parameters(self): | |
print("Time Length:", self.timeLength, ",", "Time Steps:", self.timeStep,"\n", | |
"Function:", self.function,",","Amplitude:", self.amplitude, "\n", | |
"Velocity:", self.velocity,",","Gain:", self.gain) | |
# PRINT ALL X, Y, AND PHI ARRAYS | |
def MP_printXYPHI(self): | |
print("X Values") | |
print(self.x) | |
print("Y Values") | |
print(self.y) | |
print("Phi Values") | |
print(self.phi) |