def test_toggle_field_oriented(): chassis = Chassis() field_o = chassis.field_oriented chassis.toggle_field_oriented() assert chassis.field_oriented is not field_o chassis.toggle_field_oriented() assert chassis.field_oriented is field_o
def robotInit(self): self.C = Component( ) # Components inits all connected motors, sensors, and joysticks. See inits.py. # Setup subsystems self.driverStation = wpilib.DriverStation.getInstance() self.drive = Chassis(self.C.driveTrain, self.C.gyroS, self.C.driveYEncoderS) self.lights = Lights() self.metabox = MetaBox(self.C.elevatorEncoderS, self.C.elevatorLimitS, self.C.jawsLimitS, self.C.metaboxLimitS, self.C.jawsM, self.C.elevatorM, self.C.intakeM, self.C.jawsSol) self.winch = Winch(self.C.winchM) self.power = Power() # Joysticks self.joystick = wpilib.XboxController(0) self.leftJ = wpilib.Joystick(1) # default to rainbow effect self.lights.run({'effect': 'rainbow'}) self.sd = NetworkTables.getTable('SmartDashboard') self.sd.putNumber('station', 2)
def create_component(component): """ Return the desired component. """ # Weapon components. if component == WeaponComponent.LASER: return Weapon(name='pulse laser', damage=5, min_targets=1, max_targets=5, color=libtcod.green, range=10, cost=2, rate_of_fire=10, projectile=ProjectileType.LASER_PROJECTILE) elif component == WeaponComponent.GUN: return Weapon(name='gattling gun', damage=5, min_targets=1, max_targets=3, color=libtcod.red, range=10, cost=1, rate_of_fire=4, projectile=ProjectileType.BASIC_PROJECTILE) # Chassis components. elif component == ChassisComponent.BASIC_CHASSIS: return Chassis(max_hp=30) elif component == ChassisComponent.WEAK_CHASSIS: return Chassis(max_hp=20) # Propulsion components. elif component == PropulsionComponent.BASIC_PROPULSION: return Propulsion(max_speed=12, max_impulse=2) elif component == PropulsionComponent.WEAK_PROPULSION: return Propulsion(max_speed=4, max_impulse=1) # AI components. elif component == AIComponent.DEBUG: return DoNothing() elif component == AIComponent.PROJECTILE: return ProjectileAI() return None
def test_toggle_range_holding(): chassis = Chassis() chassis.distance_pid = MagicMock() chassis.range_setpoint = 0.0 chassis.toggle_range_holding(2.0) assert chassis.range_setpoint == 2.0 chassis.toggle_range_holding(2.0) assert chassis.range_setpoint == 0.0
def test_toggle_track_vision(): chassis = Chassis() chassis.distance_pid = MagicMock() vision = chassis.track_vision chassis.toggle_vision_tracking() assert chassis.track_vision is not vision chassis.toggle_vision_tracking() assert chassis.track_vision is vision
def test_absolute(robot): epsilon = 0.01 # Tolerance for angular floating point errors (~0.05 degrees) chassis = Chassis() reset_chassis(chassis) # Absolute argument should point the modules in the absolute direction # for diagnostic purposes chassis.drive(-1.0, -1.0, 0.0, absolute=True) for module in chassis._modules.values(): assert abs(constrain_angle(module.direction + 3.0 / 4.0 * math.pi)) < epsilon reset_chassis(chassis)
def test_retain_wheel_direction(): # When the joystick is returned to the centre, keep the last direction that the wheels were pointing chassis = Chassis() for name, module in chassis._modules.items(): module.steer(math.pi / 4.0) chassis.drive(0.0, 0.0, 0.0) for name, module in chassis._modules.items(): assert abs(constrain_angle(module.direction - math.pi / 4.0)) < epsilon # Should not matter what the throttle is, even if it is zero chassis.drive(0.0, 0.0, 0.0) for name, module in chassis._modules.items(): assert abs(constrain_angle(module.direction - math.pi / 4.0)) < epsilon
def test_chassis(robot, wpilib): epsilon = 0.01 # Tolerance for angular floating point errors (~0.05 degrees) chassis = Chassis() # vX is out the left side of the robot, vY is out of the front, vZ is upwards, so a +ve rotation is counter-clockwise # vX vY vZ throttle reset_chassis(chassis) # test x axis chassis.drive(1.0, 0.0, 0.0, 1.0) for name, module in chassis._modules.items(): assert abs(constrain_angle(module.direction)) % math.pi < epsilon reset_chassis(chassis) # test y axis chassis.drive(0.0, 1.0, 0.0) for name, module in chassis._modules.items(): # test weather each module is facing in the right direction assert abs(constrain_angle(math.pi / 2.0 - module.direction)) < epsilon reset_chassis(chassis) vz = {'a': math.atan2(-Chassis.length, Chassis.width), # the angle that module a will go to if we spin on spot 'b': math.atan2(Chassis.length, Chassis.width), 'c': math.atan2(-Chassis.length, Chassis.width), 'd': math.atan2(Chassis.length, Chassis.width) } chassis.drive(0.0, 0.0, 1.0) for name, module in chassis._modules.items(): assert abs(constrain_angle(module.direction - vz[name])) < epsilon reset_chassis(chassis) chassis.drive(1.0, 1.0, 0.0) for module in chassis._modules.values(): assert abs(constrain_angle(module.direction - math.pi / 4.0)) < epsilon reset_chassis(chassis)