-
Notifications
You must be signed in to change notification settings - Fork 279
/
standing_up.py
50 lines (37 loc) · 1.71 KB
/
standing_up.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''In this exercise you need to put all code together to make the robot be able to stand up by its own.
* Task:
complete the `StandingUpAgent.standing_up` function, e.g. call keyframe motion corresponds to current posture
'''
from recognize_posture import PostureRecognitionAgent
class StandingUpAgent(PostureRecognitionAgent):
def think(self, perception):
self.standing_up()
return super(StandingUpAgent, self).think(perception)
def standing_up(self):
posture = self.posture
# YOUR CODE HERE
class TestStandingUpAgent(StandingUpAgent):
'''this agent turns off all motor to falls down in fixed cycles
'''
def __init__(self, simspark_ip='localhost',
simspark_port=3100,
teamname='DAInamite',
player_id=0,
sync_mode=True):
super(TestStandingUpAgent, self).__init__(simspark_ip, simspark_port, teamname, player_id, sync_mode)
self.stiffness_on_off_time = 0
self.stiffness_on_cycle = 10 # in seconds
self.stiffness_off_cycle = 3 # in seconds
def think(self, perception):
action = super(TestStandingUpAgent, self).think(perception)
time_now = perception.time
if time_now - self.stiffness_on_off_time < self.stiffness_off_cycle:
action.stiffness = {j: 0 for j in self.joint_names} # turn off joints
else:
action.stiffness = {j: 1 for j in self.joint_names} # turn on joints
if time_now - self.stiffness_on_off_time > self.stiffness_on_cycle + self.stiffness_off_cycle:
self.stiffness_on_off_time = time_now
return action
if __name__ == '__main__':
agent = TestStandingUpAgent()
agent.run()