Exemple #1
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 #2
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 #3
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 #4
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 #5
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()
Exemple #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #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, 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 #15
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 #16
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 #17
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 #18
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 #19
0
 def __init__(self, numlegs, legjoints):
     self.legs = [Leg(i, legjoints) for i in range(numlegs)]
Exemple #20
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 #21
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 #22
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 #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
		"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 #25
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 #27
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 #28
0
def potential_routes(start_coords, closest_stations_start, closest_stations_end, end_coords, service='mobi', method='bicycling'):
	first_legs = [Leg(start_coords, station[2], 'walking', 'None') for station in closest_stations_start]
	last_legs = [Leg(station[2], end_coords, 'walking', 'None') for station in closest_stations_end]
	first_and_last = list(product(first_legs, last_legs))
	full_routes = [(fl[0], Leg(fl[0].end_coords, fl[1].start_coords, method, service), fl[1]) for fl in first_and_last]
	return [Route(r) for r in full_routes]
Exemple #29
0
 def testDefaults(self):
     leg = Leg()
     self.assertEqual(leg.length, leg.DEFAULT_LENGTH)
     self.assertEqual(75, leg.MAX_WEIGHT)
     self.assertEqual(leg.broken, False)