Exemple #1
0
def main():

    # instantiate dynamics
    dyn = Dynamics()

    # instantiate leg
    leg = Leg(dyn, alpha=0, bound=True)

    # set boudaries
    t0 = 0
    s0 = np.array([1000, 1000, *np.random.randn(4)], dtype=float)
    l0 = np.random.randn(len(s0))
    tf = 1000
    sf = np.zeros(len(s0))
    leg.set(t0, s0, l0, tf, sf)

    # define problem
    udp = Problem(leg, atol=1e-8, rtol=1e-8)
    prob = pg.problem(udp)

    # instantiate algorithm
    uda = pg7.snopt7(True, "/usr/lib/libsnopt7_c.so")
    uda.set_integer_option("Major iterations limit", 4000)
    uda.set_integer_option("Iterations limit", 40000)
    uda.set_numeric_option("Major optimality tolerance", 1e-2)
    uda.set_numeric_option("Major feasibility tolerance", 1e-4)
    algo = pg.algorithm(uda)

    # instantiate population with one chromosome
    pop = pg.population(prob, 1)
    #pop = pg.population(prob, 0)
    #pop.push_back([1000, *l0])

    # optimise
    pop = algo.evolve(pop)
Exemple #2
0
    def __init__(self, position, rotation=90, scale=1, size=50, speed=300, turn_speed=5):
        Creature.__init__(self, position, rotation, scale, size, speed, turn_speed)

        self.head = Body(self, self.position, self.rotation, self.size, self.size, Categories.PLAYER, head=True, speed=speed)

        self.bodies.append(self.head)

        for i in range(0):
            size = self.size
            b = Body(self, self.position, self.rotation, size, size, Categories.PLAYER, speed=10)
            b.attach_to(self.bodies[i])
            self.bodies.append(b)
        
        #arm1 = Leg(self.head, 10, 90, 30, offset=(self.head.width/2, 0), foot_size=10, walk=False)
        #self.head.add_leg(arm1)
        #arm2 = Leg(self.head, 10, -90, 30, offset=(-self.head.width/2, 0), foot_size=10, walk=False)
        #self.head.add_leg(arm2)
        #self.arms.append(arm1)
        #self.arms.append(arm2)

        for body in self.bodies:
            body.add_leg(Leg(body, self.size*2, 15, 15, offset=(body.width/2 + 1, 0), foot_size=3))
            body.add_leg(Leg(body, self.size*2, -15, 15, offset=(-body.width/2 - 1, 0), foot_size=3))

        self.arm_counter = 0
Exemple #3
0
 def testSpecifics(self):
     testLength: float = 12.0
     leg = Leg(length=testLength)
     self.assertEqual(leg.length, testLength)
     self.assertEqual(leg.broken, False)
     leg.broken = True
     self.assertEqual(leg.broken, True)
Exemple #4
0
def potential_routes(start_coords,
                     closest_cars,
                     end_coords,
                     method='driving',
                     service='modo'):
    first_legs = [
        Leg(start_coords, car[1][0], 'walking', None) for car in closest_cars
    ]
    last_legs = [
        Leg(car[1][0], end_coords, method, service, additional_data=car[1][1])
        for car in closest_cars
    ]
    full_routes = zip(first_legs, last_legs)
    return [Route(r) for r in full_routes]
Exemple #5
0
    def __init__(self):
        
        '''
            Legs
        '''
        self.leg1 = Leg(1, Vector3(-61.167, 24, 98), 300)
        self.leg2 = Leg(2, Vector3(61.167, 24, 98), 60)
        self.leg3 = Let(3, Vector3(81, 24, 0), 0)
        self.leg4 = Leg(4, Vector3(61.167, 24, -98), 120)
        self.leg5 = Leg(5, Vector3(-61.167, 24, -98), 240)
        self.leg6 = Leg(6, Vector3(-81, 24, 0), 270)
        
        #leg collection
        self.legs = { 
                "FL" : self.leg1,  
                "FR" : self.leg2, 
                "MR" : self.leg3, 
                "BR" : self.leg4, 
                "BL" : self.leg5, 
                "ML" : self.leg6
        }

        '''
            Feets
        '''
        self.foot1 = self.homeFootPosition(Vector3(), leg1, Pose())
        self.foot2 = self.homeFootPosition(Vector3(), leg2, Pose())
        self.foot3 = self.homeFootPosition(Vector3(), leg3, Pose())
        self.foot4 = self.homeFootPosition(Vector3(), leg4, Pose())
        self.foot5 = self.homeFootPosition(Vector3(), leg5, Pose())
        self.foot6 = self.homeFootPosition(Vector3(), leg6, Pose())
        
        #feet collection
        self.feet = {
                "FL" : self.foot1, 
                "FR" : self.foot2, 
                "MR" : self.foot3,
                "BR" : self.foot4,
                "BL" : self.foot5,
                "ML" : self.foot6
        }

        '''
            Poses 
        '''
        self.target = Pose()
        self.lastPose = Pose()
        self.lastFeet = []
        self.nextFeet = []
Exemple #6
0
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(Point(torso_center.x, torso_center.y+15, torso_center.z))
        self.torso = Torso(Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(Point(torso_center.x+6.6, torso_center.y+8, torso_center.z))
        self.right_arm = Arm(Point(torso_center.x-6.6, torso_center.y+8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)


        if self._lower_body_flag:
            self.left_leg = Leg(Point(torso_center.x+4, torso_center.y-10.6, torso_center.z))
            self.right_leg = Leg(Point(torso_center.x-4, torso_center.y-10.6, torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)
Exemple #7
0
 def __init__(self, numlegs, legjoints):
     self.legs = [Leg(i, legjoints) for i in range(numlegs)]
     self.direction = numlegs % 2
     self.raisepos = 200
     self.manual_direction = 0
     self.leds = leds.Leds()
     self.leds.idle()
  def __init__(self, config):
    super(Body, self).__init__()
    hip_state = config.hip["state_config"].create_state()
    knee_state = config.knee["state_config"].create_state()
    hip_pins = config.hip['pins']
    knee_pins = config.hip['pins']

    legs = []
    for i in range(0, min(len(hip_pins), len(knee_pins))):
      leg = Leg(PWM, hip_pins[i], hip_state, knee_pins[i], knee_state)
      leg.set_state(state_config.create_state())
      legs.append(leg)

    # TODO - how do we define 'opposite' legs in config?
    legpair1 = LegPair(legs[0], legs[1])
    legpair2 = LegPair(legs[2], legs[3])
    self.legpairs = [legpair1, legpair2]
Exemple #9
0
 def __init__(self, numLegs : int, material : str, length : float = Leg.DEFAULT_LENGTH):
     self._legs : Sequence[Leg] = []
     if numLegs < 3:
         raise ValueError('Cannot create a chair with less than 3 legs.')
     for _ in range (0, numLegs):
         self._legs.append(Leg(length))
     
     self._numLegs = numLegs
     self._material : str = material
Exemple #10
0
 def _create_leg(self):
     download_day = datetime.datetime(year=2017, month=12, day=26)
     return Leg(price=20.0,
                departure_location='DEP',
                arrival_location='ARR',
                departure_date=download_day + datetime.timedelta(days=10),
                request_time=download_day,
                duration=datetime.timedelta(hours=2),
                airline='Qantas')
Exemple #11
0
    def copy(self):
        copy = Spider()
        copy.xy0 = self.xy0
        copy.theta = self.theta
        copy.legs = []
        for leg in self.legs:
            l = Leg(leg.index, leg.aa, leg.raised, leg.phi, leg.d)
            copy.legs.append(l)

        return copy
Exemple #12
0
    def __init__(self,
                 position,
                 rotation=90,
                 scale=1,
                 size=50,
                 speed=100,
                 turn_speed=5):
        Creature.__init__(self, position, rotation, scale, size, speed,
                          turn_speed)

        self.head = Body(self,
                         self.position,
                         self.rotation,
                         self.size * 2,
                         self.size * 2,
                         Categories.ENEMY,
                         head=True,
                         speed=speed)

        self.bodies.append(self.head)

        for i in range(4):
            b = Body(self,
                     self.position,
                     self.rotation,
                     self.size,
                     self.size,
                     Categories.ENEMY,
                     speed=30)
            b.attach_to(self.bodies[i])
            self.bodies.append(b)

        for body in self.bodies:
            leg = Leg(body, self.size * 2, 15, 40, (body.width / 2, 0), 3)
            body.add_leg(leg)
            leg = Leg(body, self.size * 2, -15, 40, (-body.width / 2, 0), 3)
            body.add_leg(leg)

        self.wander_time = 2
        self.timer = random.random() * self.wander_time

        self.displacement = Vector2(0, 0)
Exemple #13
0
	def __init__(self, config_file):
		self.config = Config()
		self.config.read_config(config_file)
		self.servos = Servos(16, self.config.mimimum_pulse, self.config.maximum_pulse, self.config.kill_angle)

		legs = []
		for i in range(4):
			leg = Leg(i, )
			leg.servos(*(self.servos.servo[x] for x in leg_pins[i]))
			leg.offsets(*offsets[i])
			leg.limbs(*lengths)
			legs.append(leg)
		self.leg0, self.leg1, self.leg2, self.leg3 = legs
Exemple #14
0
 def __init__(self,
              numLegs: int = DEFAULT_NUM_LEGS,
              material: str = DEFAULT_MATERIAL,
              length: float = Leg.DEFAULT_LENGTH):
     super(Chair, self).__init__(material)
     if numLegs < 3:
         raise ValueError('Cannot create a chair with less than 3 legs.')
     self._numLegs: int = numLegs
     self._legs: List[Leg] = []
     for _ in range(0, numLegs):
         self._legs.append(Leg(length))
Exemple #15
0
    def __init__(self):
        self.vDir = Point()
        self.vRot = Point()

        self.legs = [
            Leg(Point(0.0575, 0.0315, 0.03)),
            Leg(Point(0, 0.0315, 0.03)),
            Leg(Point(-0.0575, 0.0315, 0.03)),
            Leg(Point(0.0575, -0.0315, 0.03)),
            Leg(Point(0, -0.0315, 0.03)),
            Leg(Point(-0.0575, -0.0315, 0.03))
        ]

        #self.legs[0].position.x -= 0.04
        #self.legs[0].setPosition()

        self.legs[0].post = self.legs[1]
        self.legs[1].ante = self.legs[0]

        self.legs[1].post = self.legs[2]
        self.legs[2].ante = self.legs[1]
        
        self.legs[3].post = self.legs[4]
        self.legs[4].ante = self.legs[3]

        self.legs[4].post = self.legs[5]
        self.legs[5].ante = self.legs[4]

        #also connect front legs and rear legs to prevent them lifting at the same time
        self.legs[0].ante = self.legs[3]
        self.legs[3].ante = self.legs[0]
        self.legs[2].post = self.legs[5]
        self.legs[5].post = self.legs[2]
        pass
Exemple #16
0
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(
            Point(torso_center.x, torso_center.y + 15, torso_center.z))
        self.torso = Torso(
            Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(
            Point(torso_center.x + 6.6, torso_center.y + 8, torso_center.z))
        self.right_arm = Arm(
            Point(torso_center.x - 6.6, torso_center.y + 8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)

        if self._lower_body_flag:
            self.left_leg = Leg(
                Point(torso_center.x + 4, torso_center.y - 10.6,
                      torso_center.z))
            self.right_leg = Leg(
                Point(torso_center.x - 4, torso_center.y - 10.6,
                      torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)
Exemple #17
0
 def __init__(self, servo_kit):
     self.dimensions = [150, 300]
     self.legs = {}
     # Move servo mapping to a saveable config
     fl_map = {}
     fl_map["upper_hip"] = servo_kit.servo[0]
     fl_map["lower_hip"] = servo_kit.servo[1]
     fl_map["knee"] = servo_kit.servo[2]
     self.legs["FL"] = Leg("FL", [-75, 150, 0], fl_map)
     fr_map = {}
     fr_map["upper_hip"] = servo_kit.servo[3]
     fr_map["lower_hip"] = servo_kit.servo[4]
     fr_map["knee"] = servo_kit.servo[5]
     self.legs["FR"] = Leg("FR", [75, 150, 0], fr_map)
     bl_map = {}
     bl_map["upper_hip"] = servo_kit.servo[6]
     bl_map["lower_hip"] = servo_kit.servo[7]
     bl_map["knee"] = servo_kit.servo[8]
     self.legs["BL"] = Leg("BL", [-75, -150, 0], bl_map)
     br_map = {}
     br_map["upper_hip"] = servo_kit.servo[9]
     br_map["lower_hip"] = servo_kit.servo[10]
     br_map["knee"] = servo_kit.servo[11]
     self.legs["BR"] = Leg("BR", [75, -150, 0], br_map)
Exemple #18
0
    def __init__(self, theta=0):
        # spider dimensions
        self.R = 5
        self.h = 1

        self.xy0 = np.array([0, 0])
        self.CM = np.array([0, 0])
        self.theta = theta

        delta = 0.1
        self.legs = [
            Leg(index=i,
                attach_angle=theta - delta / 2 + (pi / 2 + delta / 3) * i,
                raised=i == 0,
                d=5 + delta * i) for i in range(4)
        ]
Exemple #19
0
    def __init__(self, config_file):
        self.config = Config()
        self.config.read_config(config_file)
        self.servos = Servos(16, self.config.mimimum_pulse, self.config.maximum_pulse, self.config.kill_angle, self.config.angle_offsets)

        legs = []
        for i in range(4):
            leg_config = self.config["leg"+str(i+1)]
            leg = Leg(leg_config["quadrants"], leg_config["positions"])
            leg.servos(*(self.servos[x] for x in leg_config["servo_pins"]))
            leg.limbs(*leg_config["limb_lengths"])
            legs.append(leg)
        self.leg0, self.leg1, self.leg2, self.leg3 = legs
Exemple #20
0
    def __init__(self, free=False, freq=45):
        self.status = 0
        '''
        Number      Status
        0           Not initialized, or initializing
        1           Working, and providing torque
        2           Limp
        '''

        self.desired_freq = freq
        self.no_limit = free

        #Walk Sequences
        self.step_counter = 0
        self.sequences = [6, 3, 0, 5, 7, 2, 1, 4]

        self.legs = [
            Leg(sel=0,
                ID1=1,
                P1=True,
                O1=1772,
                ID2=2,
                P2=False,
                O2=904,
                ID3=3,
                P3=False,
                O3=1739),  # 0: inner leg top left
            Leg(sel=1,
                ID1=4,
                P1=False,
                O1=427,
                ID2=5,
                P2=True,
                O2=-14,
                ID3=6,
                P3=True,
                O3=-435),  # 1: inner leg top right
            Leg(sel=2,
                ID1=7,
                P1=True,
                O1=-468,
                ID2=8,
                P2=True,
                O2=-25,
                ID3=9,
                P3=True,
                O3=932),  # 2: inner leg bottom left
            Leg(sel=3,
                ID1=10,
                P1=False,
                O1=14,
                ID2=11,
                P2=False,
                O2=38,
                ID3=12,
                P3=False,
                O3=-923),  # 3: inner leg bottom right
            Leg(sel=4,
                ID1=13,
                P1=True,
                O1=-1353,
                ID2=14,
                P2=False,
                O2=472,
                ID3=15,
                P3=False,
                O3=-12),  # 4: outer leg top left
            Leg(sel=5,
                ID1=16,
                P1=False,
                O1=-446,
                ID2=17,
                P2=True,
                O2=-18,
                ID3=18,
                P3=True,
                O3=-913),  # 5: outer leg top right
            Leg(sel=6,
                ID1=19,
                P1=True,
                O1=-7,
                ID2=20,
                P2=True,
                O2=5,
                ID3=21,
                P3=True,
                O3=-427),  # 6: outer leg bottom left
            Leg(sel=7,
                ID1=22,
                P1=False,
                O1=-916,
                ID2=23,
                P2=False,
                O2=-5,
                ID3=24,
                P3=False,
                O3=-906)  # 7: outer leg bottom right
        ]
        self.ser = serial.Serial('/dev/ttyO1', baudrate=500000,
                                 timeout=1)  # baudrate could be 500000, 115200
        self.reset_all_servos()
        self.push_initialize_commands()
        time.sleep(0.5)
        self.t = time.time()
Exemple #21
0
class Body:
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(
            Point(torso_center.x, torso_center.y + 15, torso_center.z))
        self.torso = Torso(
            Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(
            Point(torso_center.x + 6.6, torso_center.y + 8, torso_center.z))
        self.right_arm = Arm(
            Point(torso_center.x - 6.6, torso_center.y + 8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)

        if self._lower_body_flag:
            self.left_leg = Leg(
                Point(torso_center.x + 4, torso_center.y - 10.6,
                      torso_center.z))
            self.right_leg = Leg(
                Point(torso_center.x - 4, torso_center.y - 10.6,
                      torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)

    def horiz_move(self, gx, gy, gz):
        movement = tf.translate(Vector(
            gx, gy, gz))  # Affine matrix for horizontal movement.
        self._body_center = movement * self._init_torso_center

        self.head.horiz_move(x, y, z)
        self.torso.horiz_move(x, y, z)
        self.left_arm.horiz_move(x, y, z)
        self.right_arm.horiz_move(x, y, z)

        if self._lower_body_flag:
            self.left_leg.horiz_move(x, y, z)
            self.right_leg.horiz_move(x, y, z)

    def calc_body_center(self):
        return self._body_center

    def get_property_list(self):
        property_list = []
        property_list.extend(self.head.get_property_list())
        property_list.extend(self.torso.get_property_list())
        property_list.extend(self.left_arm.get_property_list())
        property_list.extend(self.right_arm.get_property_list())

        if self._lower_body_flag:
            property_list.extend(self.left_leg.get_property_list())
            property_list.extend(self.right_leg.get_property_list())

        return property_list

    def constr_json_data(self):
        # Construcat JSON data
        json_data_head = self.head.constr_json_data()
        json_data_torso = self.torso.constr_json_data()
        json_data_left_arm = self.left_arm.constr_json_data()
        json_data_right_arm = self.right_arm.constr_json_data()

        if self._lower_body_flag:
            json_data_left_leg = self.left_leg.constr_json_data()
            json_data_right_leg = self.right_leg.constr_json_data()

        json_data = {
            'joint_angle': {
                'left_shoulder': json_data_left_arm['joint_angle']['shoulder'],
                'left_elbow': json_data_left_arm['joint_angle']['elbow'],
                'right_shoulder':
                json_data_right_arm['joint_angle']['shoulder'],
                'right_elbow': json_data_right_arm['joint_angle']['elbow']
            },
            'true_position': {
                'head': json_data_head['true_position']['head'],
                'torso': json_data_torso['true_position']['torso'],
                'left_shouler':
                json_data_left_arm['true_position']['shoulder'],
                'left_elbow': json_data_left_arm['true_position']['elbow'],
                'left_hand': json_data_left_arm['true_position']['hand'],
                'right_shoulder':
                json_data_right_arm['true_position']['shoulder'],
                'right_elbow': json_data_right_arm['true_position']['elbow'],
                'right_hand': json_data_right_arm['true_position']['hand']
            }
        }

        if self._lower_body_flag:
            json_data['joint_angle']['left_hip'] = json_data_left_leg[
                'joint_angle']['hip']
            json_data['joint_angle']['left_knee'] = json_data_left_leg[
                'joint_angle']['knee']
            json_data['joint_angle']['right_hip'] = json_data_right_leg[
                'joint_angle']['hip']
            json_data['joint_angle']['right_knee'] = json_data_right_leg[
                'joint_angle']['knee']
            json_data['true_position']['left_hip'] = json_data_left_leg[
                'true_position']['hip']
            json_data['true_position']['left_knee'] = json_data_left_leg[
                'true_position']['knee']
            json_data['true_position']['left_foot'] = json_data_left_leg[
                'true_position']['foot']
            json_data['true_position']['right_hip'] = json_data_right_leg[
                'true_position']['hip']
            json_data['true_position']['right_knee'] = json_data_right_leg[
                'true_position']['knee']
            json_data['true_position']['right_foot'] = json_data_right_leg[
                'true_position']['foot']

        return json_data

    def set_from_json_data(self, json_data):
        # Set angle parameters from json data (not json file!)
        self.left_arm.set_from_json_data(
            json_data['joint_angle']['left_shoulder'],
            json_data['joint_angle']['left_elbow'])
        self.right_arm.set_from_json_data(
            json_data['joint_angle']['right_shoulder'],
            json_data['joint_angle']['right_elbow'])

        if self._lower_body_flag:
            self.left_leg.set_from_json_data(
                json_data['joint_angle']['left_hip'],
                json_data['joint_angle']['left_knee'])
            self.right_leg.set_from_json_data(
                json_data['joint_angle']['right_hip'],
                json_data['joint_angle']['right_knee'])

    def is_collision_body_parts(self):
        def collision_detection_generator():
            # left arm vs. cranicm
            yield self.left_arm.is_collision_to_sphere(
                self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # left arm vs. torso
            yield self.left_arm.is_collision_to_capsule(
                self.torso.calc_torso_upper_point(),
                self.torso.calc_torso_lower_point(),
                self.torso.get_torso_radius())

            # left arm vs. right upperarm
            yield self.left_arm.is_collision_to_capsule(
                self.right_arm.calc_shoulder_point(),
                self.right_arm.calc_upperarm_lower_point(),
                self.right_arm.get_upperarm_radius())

            # left arm vs. right elbow
            yield self.left_arm.is_collision_to_sphere(
                self.right_arm.calc_elbow_point(),
                self.right_arm.get_elbow_radius())

            # left arm vs. right forearm
            yield self.left_arm.is_collision_to_capsule(
                self.right_arm.calc_forearm_upper_point(),
                self.right_arm.calc_hand_point(),
                self.right_arm.get_forearm_radius())

            # right arm vs. cranicm
            yield self.right_arm.is_collision_to_sphere(
                self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # right arm vs. torso
            yield self.right_arm.is_collision_to_capsule(
                self.torso.calc_torso_upper_point(),
                self.torso.calc_torso_lower_point(),
                self.torso.get_torso_radius())

            if self._lower_body_flag:
                # left arm vs. left thigh
                yield self.left_arm.is_collision_to_capsule(
                    self.left_leg.calc_hip_point(),
                    self.left_leg.calc_thigh_lower_point(),
                    self.left_leg.get_thigh_radius())

                # left arm vs. left knee
                yield self.left_arm.is_collision_to_sphere(
                    self.left_leg.calc_knee_point(),
                    self.left_leg.get_knee_radius())

                # left arm vs. left calf
                yield self.left_arm.is_collision_to_capsule(
                    self.left_leg.calc_calf_upper_point(),
                    self.left_leg.calc_foot_point(),
                    self.left_leg.get_calf_radius())

                # left arm vs. right thigh
                yield self.left_arm.is_collision_to_capsule(
                    self.right_leg.calc_hip_point(),
                    self.right_leg.calc_thigh_lower_point(),
                    self.right_leg.get_thigh_radius())

                # left arm vs. right knee
                yield self.left_arm.is_collision_to_sphere(
                    self.right_leg.calc_knee_point(),
                    self.right_leg.get_knee_radius())

                # left arm vs. right calf
                yield self.left_arm.is_collision_to_capsule(
                    self.right_leg.calc_calf_upper_point(),
                    self.right_leg.calc_foot_point(),
                    self.right_leg.get_calf_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(
                    self.left_leg.calc_hip_point(),
                    self.left_leg.calc_thigh_lower_point(),
                    self.left_leg.get_thigh_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(
                    self.left_leg.calc_hip_point(),
                    self.left_leg.calc_thigh_lower_point(),
                    self.left_leg.get_thigh_radius())

                # right arm vs. left knee
                yield self.right_arm.is_collision_to_sphere(
                    self.left_leg.calc_knee_point(),
                    self.left_leg.get_knee_radius())

                # right arm vs. left calf
                yield self.right_arm.is_collision_to_capsule(
                    self.left_leg.calc_calf_upper_point(),
                    self.left_leg.calc_foot_point(),
                    self.left_leg.get_calf_radius())

                # right arm vs. right thigh
                yield self.right_arm.is_collision_to_capsule(
                    self.right_leg.calc_hip_point(),
                    self.right_leg.calc_thigh_lower_point(),
                    self.right_leg.get_thigh_radius())

                # right arm vs. right knee
                yield self.right_arm.is_collision_to_sphere(
                    self.right_leg.calc_knee_point(),
                    self.right_leg.get_knee_radius())

                # right arm vs. right calf
                yield self.right_arm.is_collision_to_capsule(
                    self.right_leg.calc_calf_upper_point(),
                    self.right_leg.calc_foot_point(),
                    self.right_leg.get_calf_radius())

                # left leg vs. cranicm
                yield self.left_leg.is_collision_to_sphere(
                    self.head.calc_cranicm_point(),
                    self.head.get_cranicm_radius())

                # left leg vs. right thigh
                yield self.left_leg.is_collision_to_capsule(
                    self.right_leg.calc_hip_point(),
                    self.right_leg.calc_thigh_lower_point(),
                    self.right_leg.get_thigh_radius())

                # left leg vs. right knee
                yield self.left_leg.is_collision_to_sphere(
                    self.right_leg.calc_knee_point(),
                    self.right_leg.get_knee_radius())

                # left leg vs. right calf
                yield self.left_leg.is_collision_to_capsule(
                    self.right_leg.calc_calf_upper_point(),
                    self.right_leg.calc_foot_point(),
                    self.right_leg.get_calf_radius())

                # right leg vs. cranicm
                yield self.right_leg.is_collision_to_sphere(
                    self.head.calc_cranicm_point(),
                    self.head.get_cranicm_radius())

                # torso vs. left knee
                yield self.torso.is_collision_to_sphere(
                    self.left_leg.calc_knee_point(),
                    self.left_leg.get_knee_radius())

                # torso vs. left calf
                yield self.torso.is_collision_to_capsule(
                    self.left_leg.calc_calf_upper_point(),
                    self.left_leg.calc_foot_point(),
                    self.left_leg.get_calf_radius())

                # torso vs. right knee
                yield self.torso.is_collision_to_sphere(
                    self.right_leg.calc_knee_point(),
                    self.right_leg.get_knee_radius())

                # torso vs. right calf
                yield self.torso.is_collision_to_capsule(
                    self.right_leg.calc_calf_upper_point(),
                    self.right_leg.calc_foot_point(),
                    self.right_leg.get_calf_radius())

        for detection in collision_detection_generator():
            if detection:
                return True

        return False
Exemple #22
0
		"positions": {
			**positions_left["knee"],
		}
	},
	"ankle": {
		"is_calibrated":     True,
		"index":             7,
		"pulse_width_range": [ 1200, 2650 ],
		"actuation_range":   130,
		"positions": {
			**positions_left["ankle"],
		}
	}
}

front_right = Leg(right, **front_right_config)
mid_right   = Leg(right, **mid_right_config)
back_right  = Leg(right, **back_right_config)

front_left = Leg(left, **front_left_config)
mid_left   = Leg(left, **mid_left_config)
back_left  = Leg(left, **back_left_config)

legs = [
	front_right,
	mid_right,
	back_right,
	front_left,
	mid_left,
	back_left,
]
Exemple #23
0
from turtle import Turtle
from leg import Leg
from joint import Joint

# Create animal
animal = Turtle()

# With 2 legs           
animal.addPairOfLegs(Leg(Joint(0), Joint(1), 1), Leg(Joint(2), Joint(3), -1))

def set90Degrees():
    '''Set all motors to 90 degrees'''
    animal.legPairs[0].left.knee.moveDirectTo(90)
    animal.legPairs[0].left.hip.moveDirectTo(90)
    animal.legPairs[0].right.knee.moveDirectTo(90)
    animal.legPairs[0].right.hip.moveDirectTo(90)

set90Degrees()
Exemple #24
0
               maxPulse=MAX_PULSE_B)
rhFemur = Joint(pwm,
                5,
                fLen,
                direction=1,
                minPulse=MIN_PULSE_A,
                maxPulse=MAX_PULSE_A)
rhTibia = Joint(pwm,
                6,
                tLen,
                direction=1,
                minPulse=MIN_PULSE_A,
                maxPulse=MAX_PULSE_A)

# Assign joints to legs
rfLeg = Leg(rfCoxa, rfFemur, rfTibia)
lfLeg = Leg(lfCoxa, lfFemur, lfTibia)
lhLeg = Leg(lhCoxa, lhFemur, lhTibia)
rhLeg = Leg(rhCoxa, rhFemur, rhTibia)

# Put legs into an array
body = Body(rfLeg, lfLeg, lhLeg, rhLeg)

server = None
resting = False

############################ Methods ######################


def up_down_demo():
    body.send_to_home_position(speed=10)
import numpy as np
import RPi.GPIO as GPIO
import time
from leg import Leg

# TEST

##### Servo setup #####
# For AR-3600HB Robot Servo
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

##### LEG setup #####
# Note: parameter list is: Leg(Name, horizontalShoulderServo, verticalShoulderServo, Adjacent Leg)
# only numbers for pins, servo setup happens in the Leg class.
frontRightLeg = Leg("Front Right Leg", 11, 13, None)

height = 120
width = 160
# third and twothird separate screen into 3 sections
third = width / 3
twothird = third + third
minArea = 1  # minimum area to track object
criticalArea = 13000  # area to close claws (may be too large)
move = 0  # move legs
## TIMER VARIABLES ###
cTime = 0  # current time
pTime = 0  # previous time
timeDiff = 0  # time difference since last loop
Timer = .25  #.25 # time to wait
Exemple #26
0
 def testDefaults(self):
     chair = Chair()
     leg = Leg()
     self.assertEqual(chair.numLegs, chair.DEFAULT_NUM_LEGS)
     self.assertEqual(chair.material, chair.DEFAULT_MATERIAL)
     self.assertEqual(chair.length, leg.DEFAULT_LENGTH)
Exemple #27
0
class Body:
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(Point(torso_center.x, torso_center.y+15, torso_center.z))
        self.torso = Torso(Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(Point(torso_center.x+6.6, torso_center.y+8, torso_center.z))
        self.right_arm = Arm(Point(torso_center.x-6.6, torso_center.y+8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)


        if self._lower_body_flag:
            self.left_leg = Leg(Point(torso_center.x+4, torso_center.y-10.6, torso_center.z))
            self.right_leg = Leg(Point(torso_center.x-4, torso_center.y-10.6, torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)

    def horiz_move(self, gx, gy, gz):
        movement = tf.translate(Vector(gx, gy, gz)) # Affine matrix for horizontal movement.
        self._body_center = movement * self._init_torso_center

        self.head.horiz_move(x, y, z)
        self.torso.horiz_move(x, y, z)
        self.left_arm.horiz_move(x, y, z)
        self.right_arm.horiz_move(x, y, z)

        if self._lower_body_flag:
            self.left_leg.horiz_move(x, y, z)
            self.right_leg.horiz_move(x, y, z)

    def calc_body_center(self):
        return self._body_center

    def get_property_list(self):
        property_list = []
        property_list.extend(self.head.get_property_list())
        property_list.extend(self.torso.get_property_list())
        property_list.extend(self.left_arm.get_property_list())
        property_list.extend(self.right_arm.get_property_list())

        if self._lower_body_flag:
            property_list.extend(self.left_leg.get_property_list())
            property_list.extend(self.right_leg.get_property_list())

        return property_list

    def constr_json_data(self):
        # Construcat JSON data
        json_data_head = self.head.constr_json_data()
        json_data_torso = self.torso.constr_json_data()
        json_data_left_arm = self.left_arm.constr_json_data()
        json_data_right_arm = self.right_arm.constr_json_data()
        
        if self._lower_body_flag:
            json_data_left_leg = self.left_leg.constr_json_data()
            json_data_right_leg= self.right_leg.constr_json_data()

        json_data = {
            'joint_angle': {
                'left_shoulder': json_data_left_arm['joint_angle']['shoulder'],
                'left_elbow': json_data_left_arm['joint_angle']['elbow'],
                'right_shoulder': json_data_right_arm['joint_angle']['shoulder'],
                'right_elbow': json_data_right_arm['joint_angle']['elbow']

            },
            'true_position': {
                'head': json_data_head['true_position']['head'],
                'torso': json_data_torso['true_position']['torso'],
                'left_shouler': json_data_left_arm['true_position']['shoulder'],
                'left_elbow': json_data_left_arm['true_position']['elbow'],
                'left_hand': json_data_left_arm['true_position']['hand'],
                'right_shoulder': json_data_right_arm['true_position']['shoulder'],
                'right_elbow': json_data_right_arm['true_position']['elbow'],
                'right_hand': json_data_right_arm['true_position']['hand']
            }
        }

        if self._lower_body_flag:
            json_data['joint_angle']['left_hip'] = json_data_left_leg['joint_angle']['hip']
            json_data['joint_angle']['left_knee'] = json_data_left_leg['joint_angle']['knee']
            json_data['joint_angle']['right_hip'] = json_data_right_leg['joint_angle']['hip']
            json_data['joint_angle']['right_knee'] = json_data_right_leg['joint_angle']['knee']
            json_data['true_position']['left_hip'] = json_data_left_leg['true_position']['hip']
            json_data['true_position']['left_knee'] = json_data_left_leg['true_position']['knee']
            json_data['true_position']['left_foot'] = json_data_left_leg['true_position']['foot']
            json_data['true_position']['right_hip'] = json_data_right_leg['true_position']['hip']
            json_data['true_position']['right_knee'] = json_data_right_leg['true_position']['knee']
            json_data['true_position']['right_foot'] = json_data_right_leg['true_position']['foot']

        return json_data

    def set_from_json_data(self, json_data):
        # Set angle parameters from json data (not json file!)
        self.left_arm.set_from_json_data(json_data['joint_angle']['left_shoulder'], json_data['joint_angle']['left_elbow'])
        self.right_arm.set_from_json_data(json_data['joint_angle']['right_shoulder'], json_data['joint_angle']['right_elbow'])

        if self._lower_body_flag:
            self.left_leg.set_from_json_data(json_data['joint_angle']['left_hip'], json_data['joint_angle']['left_knee'])
            self.right_leg.set_from_json_data(json_data['joint_angle']['right_hip'], json_data['joint_angle']['right_knee'])

    def is_collision_body_parts(self):

        def collision_detection_generator():
            # left arm vs. cranicm
            yield self.left_arm.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # left arm vs. torso
            yield self.left_arm.is_collision_to_capsule(self.torso.calc_torso_upper_point(), self.torso.calc_torso_lower_point(), self.torso.get_torso_radius())

            # left arm vs. right upperarm
            yield self.left_arm.is_collision_to_capsule(self.right_arm.calc_shoulder_point(), self.right_arm.calc_upperarm_lower_point(), self.right_arm.get_upperarm_radius())

            # left arm vs. right elbow
            yield self.left_arm.is_collision_to_sphere(self.right_arm.calc_elbow_point(), self.right_arm.get_elbow_radius())

            # left arm vs. right forearm
            yield self.left_arm.is_collision_to_capsule(self.right_arm.calc_forearm_upper_point(), self.right_arm.calc_hand_point(), self.right_arm.get_forearm_radius())

            # right arm vs. cranicm
            yield self.right_arm.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # right arm vs. torso
            yield self.right_arm.is_collision_to_capsule(self.torso.calc_torso_upper_point(), self.torso.calc_torso_lower_point(), self.torso.get_torso_radius())

            if self._lower_body_flag:
                # left arm vs. left thigh
                yield self.left_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # left arm vs. left knee
                yield self.left_arm.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # left arm vs. left calf
                yield self.left_arm.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # left arm vs. right thigh
                yield self.left_arm.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # left arm vs. right knee
                yield self.left_arm.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # left arm vs. right calf
                yield self.left_arm.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # right arm vs. left knee
                yield self.right_arm.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # right arm vs. left calf
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # right arm vs. right thigh
                yield self.right_arm.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # right arm vs. right knee
                yield self.right_arm.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # right arm vs. right calf
                yield self.right_arm.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # left leg vs. cranicm
                yield self.left_leg.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

                # left leg vs. right thigh
                yield self.left_leg.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # left leg vs. right knee
                yield self.left_leg.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # left leg vs. right calf
                yield self.left_leg.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # right leg vs. cranicm
                yield self.right_leg.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

                # torso vs. left knee
                yield self.torso.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # torso vs. left calf
                yield self.torso.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # torso vs. right knee
                yield self.torso.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # torso vs. right calf
                yield self.torso.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

        for detection in collision_detection_generator():
            if detection:
                return True

        return False
Exemple #28
0
 def __init__(self, cog, m, f, s):
     self.cog = cog
     self.m = m
     self.f = f
     self.s = s
     self.f1 = Leg(45, (0, 70), (f, s, 0), (15, 15), "f1")
     self.f2 = Leg(135, (0, 70), (-f, s, 0), (15, 15), "f2")
     self.m1 = Leg(0, (0, 70), (m, 0, 0), (15, 15), "m1")
     self.m2 = Leg(180, (0, 70), (-m, 0, 0), (15, 15), "m2")
     self.b1 = Leg(315, (0, 70), (f, -s, 0), (15, 15), "b1")
     self.b2 = Leg(225, (0, 70), (-f, -s, 0), (15, 15), "b2")
     self.functional = [True]*6
Exemple #29
0
class Robot:
    def __init__(self, cog, m, f, s):
        self.cog = cog
        self.m = m
        self.f = f
        self.s = s
        self.f1 = Leg(45, (0, 70), (f, s, 0), (15, 15), "f1")
        self.f2 = Leg(135, (0, 70), (-f, s, 0), (15, 15), "f2")
        self.m1 = Leg(0, (0, 70), (m, 0, 0), (15, 15), "m1")
        self.m2 = Leg(180, (0, 70), (-m, 0, 0), (15, 15), "m2")
        self.b1 = Leg(315, (0, 70), (f, -s, 0), (15, 15), "b1")
        self.b2 = Leg(225, (0, 70), (-f, -s, 0), (15, 15), "b2")
        self.functional = [True]*6

    def get_polygon(self):
        x_cor = [self.m+self.cog[0], self.f+self.cog[0], -self.f+self.cog[0], -self.m+self.cog[0], -self.f+self.cog[0], self.f+self.cog[0], self.m+self.cog[0]]
        y_cor = [self.cog[1], self.s+self.cog[1], self.s+self.cog[1], self.cog[1], -self.s+self.cog[1], -self.s+self.cog[1], self.cog[1]]
        z_cor = [0, 0, 0, 0, 0, 0, 0]
        return (x_cor, y_cor, z_cor, "polygon")
    
    def get_cords(self):
        x_cor = []
        y_cor = []
        z_cor = []
        label = []
        pol_cor = self.get_polygon()
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.f1.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.f2.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.m1.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.m2.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.b1.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        pol_cor = self.b2.abs_cordinates(self.cog)
        x_cor.append(pol_cor[0])
        y_cor.append(pol_cor[1])
        z_cor.append(pol_cor[2])
        label.append(pol_cor[3])
        return [x_cor, y_cor, z_cor, label] 

    def simulate_tripod(self, inc, time):
        frames = []
        self.f1.inc_up_angle(inc/2)
        self.m2.inc_up_angle(inc/2)
        self.b1.inc_up_angle(inc/2)
        self.m1.inc_up_angle(inc/2)
        self.b2.inc_up_angle(inc/2)
        self.f2.inc_up_angle(inc/2)
        frames.append(self.get_cords())
        for i in range(time):
            self.f2.inc_up_angle(-inc/2)
            self.m1.inc_up_angle(-inc/2)
            self.b2.inc_up_angle(-inc/2)
            self.m2.inc_up_angle(-inc/2)
            self.b1.inc_up_angle(-inc/2)
            self.f1.inc_up_angle(-inc/2)
            self.f2.inc_below_angle(-inc)
            self.m2.inc_below_angle(-inc)
            self.b2.inc_below_angle(-inc)
            frames.append(self.get_cords())
            self.f2.inc_up_angle(-inc/2)
            self.m1.inc_up_angle(-inc/2)
            self.b2.inc_up_angle(-inc/2)
            self.m2.inc_up_angle(-inc/2)
            self.b1.inc_up_angle(-inc/2)
            self.f1.inc_up_angle(-inc/2)
            self.f2.inc_below_angle(inc)
            self.m2.inc_below_angle(inc)
            self.b2.inc_below_angle(inc)
            frames.append(self.get_cords())
            self.cog = (self.cog[0], self.cog[1]+5, self.cog[2])
            self.f2.inc_up_angle(inc/2)
            self.m1.inc_up_angle(inc/2)
            self.b2.inc_up_angle(inc/2)
            self.m2.inc_up_angle(inc/2)
            self.b1.inc_up_angle(inc/2)
            self.f1.inc_up_angle(inc/2)
            self.m1.inc_below_angle(-inc)
            self.b1.inc_below_angle(-inc)
            self.f1.inc_below_angle(-inc)
            frames.append(self.get_cords())
            self.f2.inc_up_angle(inc/2)
            self.m1.inc_up_angle(inc/2)
            self.b2.inc_up_angle(inc/2)
            self.m2.inc_up_angle(inc/2)
            self.b1.inc_up_angle(inc/2)
            self.f1.inc_up_angle(inc/2)
            self.m1.inc_below_angle(inc)
            self.b1.inc_below_angle(inc)
            self.f1.inc_below_angle(inc)
            frames.append(self.get_cords())
            self.cog = (self.cog[0], self.cog[1]+5, self.cog[2])
        return frames 
    
    def simulate_ripple(self, inc, time):
        frames = []
        self.f1.inc_up_angle(inc/2)
        self.f2.inc_up_angle(-inc/4)
        self.m1.inc_up_angle(-inc/4)
        self.m2.inc_up_angle(-inc/2)
        self.b1.inc_up_angle(-inc/4)
        self.b2.inc_up_angle(-inc/4)
        frames.append(self.get_cords())
        for i in range(time):
            self.f1.inc_up_angle(-inc/2)
            self.f2.inc_up_angle(inc/4)
            self.m1.inc_up_angle(inc/4)
            self.m2.inc_up_angle(inc/2)
            self.b1.inc_up_angle(inc/4)
            self.b2.inc_up_angle(inc/4)
            self.f1.inc_below_angle(-inc)
            self.m2.inc_below_angle(-inc)
            frames.append(self.get_cords())
            self.f1.inc_up_angle(-inc/2)
            self.f2.inc_up_angle(inc/4)
            self.m1.inc_up_angle(inc/4)
            self.m2.inc_up_angle(inc/2)
            self.b1.inc_up_angle(inc/4)
            self.b2.inc_up_angle(inc/4)
            self.f1.inc_below_angle(inc)
            self.m2.inc_below_angle(inc)
            frames.append(self.get_cords())
            self.cog = (self.cog[0], self.cog[1]+5, self.cog[2])
            self.f1.inc_up_angle(inc/4)
            self.f2.inc_up_angle(inc/4)
            self.m1.inc_up_angle(-inc/2)
            self.m2.inc_up_angle(-inc/4)
            self.b1.inc_up_angle(inc/4)
            self.b2.inc_up_angle(-inc/2)
            self.m1.inc_below_angle(-inc)
            self.b2.inc_below_angle(-inc)
            frames.append(self.get_cords())
            self.f1.inc_up_angle(inc/4)
            self.f2.inc_up_angle(inc/4)
            self.m1.inc_up_angle(-inc/2)
            self.m2.inc_up_angle(-inc/4)
            self.b1.inc_up_angle(inc/4)
            self.b2.inc_up_angle(-inc/2)
            self.m1.inc_below_angle(inc)
            self.b2.inc_below_angle(inc)
            frames.append(self.get_cords())
            self.cog = (self.cog[0], self.cog[1]+5, self.cog[2])
            self.f1.inc_up_angle(inc/4)
            self.f2.inc_up_angle(-inc/2)
            self.m1.inc_up_angle(inc/4)
            self.m2.inc_up_angle(-inc/4)
            self.b1.inc_up_angle(-inc/2)
            self.b2.inc_up_angle(inc/4)
            self.f2.inc_below_angle(-inc)
            self.b1.inc_below_angle(-inc)
            frames.append(self.get_cords())
            self.f1.inc_up_angle(inc/4)
            self.f2.inc_up_angle(-inc/2)
            self.m1.inc_up_angle(inc/4)
            self.m2.inc_up_angle(-inc/4)
            self.b1.inc_up_angle(-inc/2)
            self.b2.inc_up_angle(inc/4)
            self.f2.inc_below_angle(inc)
            self.b1.inc_below_angle(inc)
            frames.append(self.get_cords())
            self.cog = (self.cog[0], self.cog[1]+5, self.cog[2])
        return frames

    def fault(self, arr):
        for leg in arr:
            self.functional[leg.index] = False
            leg._disable()
        self.reconfigure()

    def recover(self, arr):
        for leg in arr:
            self.functional[leg.index] = True
            leg._enable()
        self.reconfigure()
    
    def get_number_legs(self):
        num = 0
        for leg in self.functional:
            if leg:
                num = num+1
        return num

    def reconfigure(self):
        num = self.get_number_legs()
        if num == 6:
            self.simulate_ripple()
            # do nothing
        else if num == 5:
            # disable one odd leg walk with four legs
        else if num == 4:
            # reconfigure according to the position of functional legs
        else if num == 3:
            # disable one odd leg, crawl witb two legs
        else if num == 2:
            # reconfigure according to the position of legs and then crawl
        else:
            # crawl
        return
            
    def walk(self):
        return
    
    def crawl(Self):
        return
Exemple #30
0
#!/usr/bin/env python3
'''
ENGLISH.py
constants for english word database
'''

from leg import Leg

ZBOUND, ZCOUNT = 1500, 2
ABOUND, ACOUNT = 35000, 3
BBOUND, BCOUNT = 36500, 3
CBOUND, CCOUNT = None, 2
LEX_EN = "../resources/lexwords/lex_filter_2.txt"

LEGS_EN = (
    Leg(0, ZBOUND, ZCOUNT, "Z"),  # group Z
    Leg(ZBOUND, ABOUND, ACOUNT, "A"),  # group A
    Leg(ABOUND, BBOUND, BCOUNT, "B"),  # group B
    Leg(BBOUND, CBOUND, CCOUNT, "C")  # group C
)
Exemple #31
0
    def _create_legs(self, segment_data):
        """Creates the Leg objects for this journey using segments in the
        slice data.

        Args:
            segment_data (dict): the "segment" object of the query response.

        Returns:
            Leg[]: an array of Leg objects for this Journey.
        """
        legs = []

        for segment in segment_data:

            leg_data = segment["leg"][0]

            # extract origin
            leg_origin = {
                "code": leg_data["origin"],
                "name": None,
                "city": None
            }
            for airport in self.ap_list:
                if airport["code"] == leg_origin["code"]:
                    leg_origin["name"] = airport["name"]
                    for city in self.city_list:
                        if city["code"] == airport["city"]:
                            leg_origin["city"] = city["name"]

            # extract destination
            leg_dest = {
                "code": leg_data["destination"],
                "name": None,
                "city": None
            }
            for airport in self.ap_list:
                if airport["code"] == leg_dest["code"]:
                    leg_dest["name"] = airport["name"]
                    for city in self.city_list:
                        if city["code"] == airport["city"]:
                            leg_dest["city"] = city["name"]

            # extract departure and arrival time
            leg_dept_time = convert_str_to_date(leg_data["departureTime"])
            leg_arr_time = convert_str_to_date(leg_data["arrivalTime"])

            # extract flight details
            leg_flight_carrier = segment["flight"]["carrier"]
            leg_flight_number = segment["flight"]["number"]
            leg_flight = {
                "carrier": leg_flight_carrier,
                "number": leg_flight_number,
                "name": None
            }
            # get carrier name from "data" object
            for carrier in self.carrier_list:
                if carrier["code"] == leg_flight["carrier"]:
                    leg_flight["name"] = carrier["name"]

            # extract aircraft details
            leg_ac_code = leg_data["aircraft"]
            leg_aircraft = {"code": leg_ac_code, "name": None}
            # get aircraft name from "data" object
            for aircraft in self.ac_list:
                if aircraft["code"] == leg_ac_code:
                    leg_aircraft["name"] = aircraft["name"]

            # extract duration
            leg_duration = leg_data["duration"]

            # create new Leg object
            this_leg = Leg(leg_origin, leg_dest, leg_dept_time, leg_arr_time,
                           leg_flight, leg_aircraft, leg_duration)

            legs.append(this_leg)

        return legs
Exemple #32
0
 def __init__(self, numlegs, legjoints):
     self.legs = [Leg(i, legjoints) for i in range(numlegs)]
Exemple #33
0
 def testDefaults(self):
     leg = Leg()
     self.assertEqual(leg.length, leg.DEFAULT_LENGTH)
     self.assertEqual(75, leg.MAX_WEIGHT)
     self.assertEqual(leg.broken, False)