def CreatePod(self, deploymentLabel): print("Creating pod...") #Get deployment deployment = next((x for x in self.GetDeployments() if x.deploymentLabel == deploymentLabel), None) #Create name deployment.currentReplicas += 1 name = deploymentLabel + str(deployment.currentReplicas) #Create and add pod pod = Pod(name, deployment.cpuCost, deployment.cpuCost, deploymentLabel) self.GetPending().append(pod) print("Done. Current pending pods =", len(self.GetPending()), sep=' ')
def __init__(self, position, m, l, theta): """init SpacePod object with a position, length, and orientation """ # x,y are the center of the pod # position is an [2,1] np.array: self.position = position % win_size # l is the length of a side of the pod self.l = l # m is the mass of the pod self.m = m # theta is the angle of the 'front' # to the center (in radians!) self.theta = theta % (2 * np.pi) # set our graphics body object self.setBody() # set the 'internal' pod and its control system self.pd = Pd(m, l)
class SpacePod: def __init__(self, position, m, l, theta): """init SpacePod object with a position, length, and orientation """ # x,y are the center of the pod # position is an [2,1] np.array: self.position = position % win_size # l is the length of a side of the pod self.l = l # m is the mass of the pod self.m = m # theta is the angle of the 'front' # to the center (in radians!) self.theta = theta % (2 * np.pi) # set our graphics body object self.setBody() # set the 'internal' pod and its control system self.pd = Pd(m, l) def setOrientation(self, theta): self.theta = theta def setBody(self): """create a graphics polygon representing the SpacePod """ # create a rotation matrix rotMat = np.matrix([ [np.cos(self.theta), -np.sin(self.theta)], [np.sin(self.theta), np.cos(self.theta)] ]) # create a body matrix relative to the pod's center of mass bodyMat = np.matrix([ [ -self.l / 2, -self.l / 2], [ self.l / 2, self.l / 2], [ -self.l / 2, self.l / 2], [ self.l / 2, -self.l / 2] ]) bodyMat.shape = (2,4) # rotate and translate the bodyMat to create the # pod's position posMat = (rotMat * bodyMat + self.position) % win_size # convert to vertices for graphics lib vertices = [Point(int(posMat[0, i]), int(posMat[1, i])) for i in range(4)] self.body = Polygon(vertices) def display(self): self.body.draw(win) def erase(self): self.body.undraw() def move(self, dpos, dtheta): self.position = (self.position + dpos) % win_size self.theta += dtheta self.setBody() def calcNewGlobalVel(self, v, w): percent = .7 # set this locally for now rotMat_to_bf = np.matrix([ [np.cos(self.theta), np.sin(self.theta)], [-np.sin(self.theta), np.cos(self.theta)] ]) rotMat_from_bf = np.matrix([ [np.cos(self.theta), -np.sin(self.theta)], [np.sin(self.theta), np.cos(self.theta)] ]) # change v to body-fixed coords bf_v = rotMat_to_bf * v v_calc = np.concatenate([bf_v, np.matrix([0])], axis = 0) w_calc = np.transpose(np.concatenate([np.matrix([0,0]), np.matrix([w])], axis = 1)) # calculate thruster forces and # estimate the changes in velocity vdot = self.pd.calcNewLocalVel(v_calc, w_calc, percent) # change the velocities accordingly # and rotate out of the body-fixed frame new_bf_v = (v_calc - vdot[0:3])[0:2] new_v = rotMat_from_bf * new_bf_v new_w = float((w_calc - vdot[3:6])[2]) return new_v, new_w