Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sprint(motors):
- mutex.acquire()
- # bodyHeight between -50 -- 175
- stepHeight = 60.0
- speedFactor = sp.getSpeed()
- n_steps = sp.getNumberOfSteps()
- forLoopRange = int(n_steps)
- moving_time = 1.25
- sleep_factor = sp.getSleepFactor()
- sleeptime = (moving_time / (speedFactor * sleep_factor)) + 0.1
- speedFactor = 1.1
- step = 120.0 #normale step
- bodyHeight = 130.0
- centerShift = 0
- resetBreadth = sp.getResetBreadth()
- walkBreadth = 60.0
- sprintRaise = False
- ookNeerzetten = False
- raise_sleep_time = 0.15
- midTurn_Two = 0
- midTurn_Five = 0
- try:
- while True:
- # midTurn update
- if sp.step_factor_y < 0:
- midTurn_Two = sp.step_factor_y * 20.0
- midTurn_Five = 0
- else:
- midTurn_Two = 0
- midTurn_Five = sp.step_factor_y * 20.0
- # midTurn = sp.step_factor_y * 20.0
- # midTurn = 0
- ##########################################
- # Extra optillen
- ##########################################
- if (math.sqrt(math.pow(sp.step_factor_x, 2) + math.pow(sp.step_factor_y, 2))) < 0.8:
- sprintRaise = True
- dest_x1 = 0
- dest_x3 = -step
- dest_x5 = (-step / 2.0) - midTurn_Five
- dest_y = 100
- moving_time = 0.417
- sleeptime = raise_sleep_time
- # 1, 3, 5 optillen
- ids1, pos1, speed1 = moveLeg(1, speedFactor, bodyHeight, dest_x1, dest_y, -stepHeight,
- moving_time)
- ids2, pos2, speed2 = moveLeg(3, speedFactor, bodyHeight, dest_x3, dest_y, -stepHeight, moving_time)
- ids3, pos3, speed3 = moveLeg(5, speedFactor, bodyHeight, dest_x5, dest_y + walkBreadth, -stepHeight, moving_time)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3),
- (pos1 + pos2 + pos3),
- (speed1 + speed2 + speed3))
- time.sleep(sleeptime)
- else:
- sprintRaise = False
- ###########################################################################################################
- # DRIEHOEKSBEWEGING 1
- ###########################################################################################################
- dest_x2 = -(step / 2.0) - midTurn_Two
- dest_x4 = 0
- dest_x6 = -step
- dest_x1 = step
- dest_x3 = 0
- dest_x5 = (step / 2.0) - midTurn_Five
- dest_y = 100
- if(ookNeerzetten):
- dest_z = -stepHeight
- else:
- dest_z = 0
- moving_time = 1.0
- sleeptime = 0.238
- # sleeptime = (moving_time / (speedFactor * sleep_factor)) + (0.05 * n_steps)
- # 1, 3, 5 door de lucht en 2, 4, 6 over de grond
- ids1, pos1, speed1 = moveLegStraight(2, speedFactor, bodyHeight, dest_x2, dest_y + walkBreadth, 0, moving_time)
- ids2, pos2, speed2 = moveLegStraight(4, speedFactor, bodyHeight, dest_x4, dest_y, 0, moving_time)
- ids3, pos3, speed3 = moveLegStraight(6, speedFactor, bodyHeight, dest_x6, dest_y, 0, moving_time)
- ids4, pos4, speed4 = moveLeg(1, speedFactor, bodyHeight, (step / 2.0), dest_y, -stepHeight, moving_time / 2.0)
- ids5, pos5, speed5 = moveLeg(3, speedFactor, bodyHeight, -(step / 2.0), dest_y, -stepHeight, moving_time / 2.0)
- ids6, pos6, speed6 = moveLeg(5, speedFactor, bodyHeight, 0, dest_y + walkBreadth, -stepHeight, moving_time / 2.0)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3 + ids4 + ids5 + ids6),
- (pos1 + pos2 + pos3 + pos4 + pos5 + pos6),
- (speed1 + speed2 + speed3 + speed4 + speed5 + speed6))
- time.sleep(sleeptime / n_steps)
- ids1, pos1, speed1 = moveLegStraight(2, speedFactor, bodyHeight, dest_x2, dest_y + walkBreadth, 0, moving_time, 2)
- ids2, pos2, speed2 = moveLegStraight(4, speedFactor, bodyHeight, dest_x4, dest_y, 0, moving_time, 2)
- ids3, pos3, speed3 = moveLegStraight(6, speedFactor, bodyHeight, dest_x6, dest_y, 0, moving_time, 2)
- ids4, pos4, speed4 = moveLeg(1, speedFactor, bodyHeight, dest_x1, dest_y, dest_z, moving_time / 2.0)
- ids5, pos5, speed5 = moveLeg(3, speedFactor, bodyHeight, dest_x3, dest_y, dest_z, moving_time / 2.0)
- ids6, pos6, speed6 = moveLeg(5, speedFactor, bodyHeight, dest_x5, dest_y + walkBreadth, dest_z, moving_time / 2.0)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3 + ids4 + ids5 + ids6),
- (pos1 + pos2 + pos3 + pos4 + pos5 + pos6),
- (speed1 + speed2 + speed3 + speed4 + speed5 + speed6))
- time.sleep(sleeptime / n_steps)
- ##########################################
- # Extra neerzetten
- ##########################################
- if (sprintRaise and ookNeerzetten):
- dest_x1 = step
- dest_x3 = 0
- dest_x5 = (step / 2.0) - midTurn_Five
- dest_y = 100
- moving_time = 0.417
- sleeptime = raise_sleep_time
- # 1, 3, 5 neertillen
- ids1, pos1, speed1 = moveLeg(1, speedFactor, bodyHeight, dest_x1, dest_y, 0,
- moving_time)
- ids2, pos2, speed2 = moveLeg(3, speedFactor, bodyHeight, dest_x3, dest_y, 0, moving_time)
- ids3, pos3, speed3 = moveLeg(5, speedFactor, bodyHeight, dest_x5, dest_y + walkBreadth, 0,
- moving_time)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3),
- (pos1 + pos2 + pos3),
- (speed1 + speed2 + speed3))
- time.sleep(sleeptime)
- if not sp.current_action == 'SPRINT':
- break
- # midTurn update
- if sp.step_factor_y < 0:
- midTurn_Two = sp.step_factor_y * 20.0
- midTurn_Five = 0
- else:
- midTurn_Two = 0
- midTurn_Five = sp.step_factor_y * 20.0
- # midTurn = sp.step_factor_y * 20.0
- # midTurn = 0
- ##########################################
- # Extra optillen
- ##########################################
- if (math.sqrt(math.pow(sp.step_factor_x, 2) + math.pow(sp.step_factor_y, 2))) < 0.8:
- sprintRaise = True
- dest_x2 = -(step / 2.0) - midTurn_Two
- dest_x4 = 0
- dest_x6 = -step
- dest_y = 100
- moving_time = 0.417
- sleeptime = raise_sleep_time
- # 2, 4, 6 optillen
- ids1, pos1, speed1 = moveLeg(2, speedFactor, bodyHeight, dest_x2, dest_y + walkBreadth, -stepHeight,
- moving_time)
- ids2, pos2, speed2 = moveLeg(4, speedFactor, bodyHeight, dest_x4, dest_y, -stepHeight, moving_time)
- ids3, pos3, speed3 = moveLeg(6, speedFactor, bodyHeight, dest_x6, dest_y, -stepHeight, moving_time)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3),
- (pos1 + pos2 + pos3),
- (speed1 + speed2 + speed3))
- time.sleep(sleeptime)
- else:
- sprintRaise = False
- ###########################################################################################################
- # DRIEHOEKSBEWEGING 2
- ###########################################################################################################
- dest_x1 = 0
- dest_x3 = -step
- dest_x5 = (-step / 2.0) + midTurn_Five
- dest_x2 = (step / 2.0) + midTurn_Two
- dest_x4 = (step)
- dest_x6 = 0
- dest_y = 100
- if (ookNeerzetten):
- dest_z = -stepHeight
- else:
- dest_z = 0
- moving_time = 1.0
- # sleeptime = (moving_time / (speedFactor * sleep_factor)) + (0.05 * n_steps)
- sleeptime = 0.238
- # Poten 1, 3, 5 over de grond en Poten 2, 4, 6 door de lucht
- ids1, pos1, speed1 = moveLegStraight(1, speedFactor, bodyHeight, dest_x1, dest_y, 0, moving_time)
- ids2, pos2, speed2 = moveLegStraight(3, speedFactor, bodyHeight, dest_x3, dest_y, 0, moving_time)
- ids3, pos3, speed3 = moveLegStraight(5, speedFactor, bodyHeight, dest_x5, dest_y + walkBreadth, 0, moving_time)
- ids4, pos4, speed4 = moveLeg(2, speedFactor, bodyHeight, 0, dest_y + walkBreadth, -stepHeight, moving_time / 2.0)
- ids5, pos5, speed5 = moveLeg(4, speedFactor, bodyHeight, (step / 2.0), dest_y, -stepHeight, moving_time / 2.0)
- ids6, pos6, speed6 = moveLeg(6, speedFactor, bodyHeight, -(step / 2.0), dest_y, -stepHeight, moving_time / 2.0)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3 + ids4 + ids5 + ids6),
- (pos1 + pos2 + pos3 + pos4 + pos5 + pos6),
- (speed1 + speed2 + speed3 + speed4 + speed5 + speed6))
- time.sleep(sleeptime / n_steps)
- ids1, pos1, speed1 = moveLegStraight(1, speedFactor, bodyHeight, dest_x1, dest_y, 0, moving_time, 2)
- ids2, pos2, speed2 = moveLegStraight(3, speedFactor, bodyHeight, dest_x3, dest_y, 0, moving_time, 2)
- ids3, pos3, speed3 = moveLegStraight(5, speedFactor, bodyHeight, dest_x5, dest_y + walkBreadth, 0, moving_time, 2)
- ids4, pos4, speed4 = moveLeg(2, speedFactor, bodyHeight, dest_x2, dest_y + walkBreadth, dest_z, moving_time / 2.0)
- ids5, pos5, speed5 = moveLeg(4, speedFactor, bodyHeight, dest_x4, dest_y, dest_z, moving_time / 2.0)
- ids6, pos6, speed6 = moveLeg(6, speedFactor, bodyHeight, dest_x6, dest_y, dest_z, moving_time / 2.0)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3 + ids4 + ids5 + ids6),
- (pos1 + pos2 + pos3 + pos4 + pos5 + pos6),
- (speed1 + speed2 + speed3 + speed4 + speed5 + speed6))
- time.sleep(sleeptime / n_steps)
- ##########################################
- # Extra neerzetten
- ##########################################
- if (sprintRaise and ookNeerzetten):
- dest_x2 = (step / 2.0) + midTurn_Two
- dest_x4 = (step)
- dest_x6 = 0
- dest_y = 100
- moving_time = 0.417
- sleeptime = raise_sleep_time
- # 2, 4, 6 neerzetten
- ids1, pos1, speed1 = moveLeg(2, speedFactor, bodyHeight, dest_x2, dest_y + walkBreadth, 0,
- moving_time)
- ids2, pos2, speed2 = moveLeg(4, speedFactor, bodyHeight, dest_x4, dest_y, 0, moving_time)
- ids3, pos3, speed3 = moveLeg(6, speedFactor, bodyHeight, dest_x6, dest_y, 0, moving_time)
- getChain().sync_write_pos_speed((ids1 + ids2 + ids3),
- (pos1 + pos2 + pos3),
- (speed1 + speed2 + speed3))
- time.sleep(sleeptime)
- if not sp.current_action == 'SPRINT':
- break
- finally:
- mutex.release()
- # if not sp.current_action == 'WALK' and not sp.current_action == 'TURN' and not sp.current_action == 'TURNWALK':
- resetSpiderAllOnGround(speedFactor)
- # else:
- # sp.ready_for_action = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement