def setUp(self): self.headx_cmd_test = Command('headx',0,0,0) self.headz_cmd_test = Command('headz',0,0,0) self.vel_cmd_test = Command('vel',0.3,0,0) self.airplane_test = ManeuveredAirplane(v0 = 0.3, command_list = [self.headx_cmd_test, self.headz_cmd_test, self.vel_cmd_test])
def setUp(self): self.head_cmd_test = Command('head', 0, 0, 0) self.vel_cmd_test = Command('vel', 0.3, 0, 0) self.bicycle_test = ManeuveredBicycle( x0=0, y0=0, v0=0.3, h0=0, command_list=[self.head_cmd_test, self.vel_cmd_test])
def __init__(self, x0=0, y0=0, z0=0, v0=0, hz0=0, hx0=0, command_list=None, dt=1.): if command_list == None: headx_cmd = Command('headx', 0, 0, 0) headz_cmd = Command('headz', 0, 0, 0) vel_cmd = Command('vel', 0, 0, 0) command_list = [headx_cmd, headz_cmd, vel_cmd] super().__init__(command_list) self.x = x0 # Position along x-axis. self.y = y0 # Position along y-axis. self.z = z0 # Position along y-axis. self.vel = v0 # Velocity. self.headz = hz0 # Heading around z-axis. self.headx = hx0 # Heading around x-axis. self.dt = dt # Time unit
The change function should be called through the change_command function defined under the ManeuveredSystem abstract class. ''' cmd_vel = self.commands['vel'] cmd_vel.value = speed cmd_vel.steps = steps cmd_vel.delta = (cmd_vel.value - self.vel) / cmd_vel.steps if abs(cmd_vel.delta) > 0: cmd_vel.steps = steps else: cmd_vel.steps = 0 if __name__ == "__main__": # Route generation example with a ManeuveredAirplane headx_cmd = Command('headx', 0, 0, 0) headz_cmd = Command('headz', 0, 0, 0) vel_cmd = Command('vel', 1, 0, 0) airplane = ManeuveredAirplane(x0=1000, y0=1000, z0=1, v0=0, hx0=0, hz0=0, command_list=[headx_cmd, headz_cmd, vel_cmd]) xs, ys, zs = [], [], [] states = [] # Take off acceleration objective airplane.change_command("vel", 200, 20) # First phase -> Acceleration
def test_command_equality(self): self.assertEqual(self.commandTest, Command("velocity", 0, 1, 2))
def setUp(self): self.commandTest = Command("velocity", 0, 1, 2)
def test_initial_velocity_command_in_commands(self): self.assertEqual(self.airplane_test.commands['vel'],Command('vel',0.3,0,0))
def test_initial_headingz_command_in_commands(self): self.assertEqual(self.airplane_test.commands['headz'],Command('headz',0,0,0))
def test_initial_velocity_command(self): self.assertEqual(self.vel_cmd_test,Command('vel',0.3,0,0))
def test_initial_headingz_command(self): self.assertEqual(self.headz_cmd_test,Command('headz',0,0,0))
def test_initial_heading_command_in_commands(self): self.assertEqual(self.bicycle_test.commands['head'], Command('head', 0, 0, 0))
''' cmd_vel = self.commands['vel'] cmd_vel.value = speed cmd_vel.steps = steps cmd_vel.delta = (cmd_vel.value - self.vel) / cmd_vel.steps if abs(cmd_vel.delta) > 0: cmd_vel.steps = steps else: cmd_vel.steps = 0 if __name__ == "__main__": # ======== Route generation example with a ManeuveredBicycle ======== sensor_std = 1. head_cmd = Command('head', 0, 0, 0) vel_cmd = Command('vel', 0.3, 0, 0) bicycle = ManeuveredBicycle(x0=0, y0=0, v0=0.3, h0=0, command_list=[head_cmd, vel_cmd]) xs, ys = [], [] # First phase for i in range(30): x, y = bicycle.update() xs.append(x) ys.append(y) # Change in commands