forked from ediaro23/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.py
66 lines (43 loc) · 1.85 KB
/
control.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 6 15:32:51 2023
@author: stonneau
"""
import numpy as np
from bezier import Bezier
# in my solution these gains were good enough for all joints but you might want to tune this.
Kp = 300. # proportional gain (P of PD)
Kv = 2 * np.sqrt(Kp) # derivative gain (D of PD)
def controllaw(sim, robot, trajs, tcurrent, cube):
q, vq = sim.getpybulletstate()
#TODO
torques = [0.0 for _ in sim.bulletCtrlJointsInPinOrder]
sim.step(torques)
if __name__ == "__main__":
from tools import setupwithpybullet, setupwithpybulletandmeshcat, rununtil
from config import DT
robot, sim, cube = setupwithpybullet()
from config import CUBE_PLACEMENT, CUBE_PLACEMENT_TARGET
from inverse_geometry import computeqgrasppose
from path import computepath
q0,successinit = computeqgrasppose(robot, robot.q0, cube, CUBE_PLACEMENT, None)
qe,successend = computeqgrasppose(robot, robot.q0, cube, CUBE_PLACEMENT_TARGET, None)
path = computepath(q0,qe,CUBE_PLACEMENT, CUBE_PLACEMENT_TARGET)
#setting initial configuration
sim.setqsim(q0)
#TODO this is just an example, you are free to do as you please.
#In any case this trajectory does not follow the path
#0 init and end velocities
def maketraj(q0,q1,T): #TODO compute a real trajectory !
q_of_t = Bezier([q0,q0,q1,q1],t_max=T)
vq_of_t = q_of_t.derivative(1)
vvq_of_t = vq_of_t.derivative(1)
return q_of_t, vq_of_t, vvq_of_t
#TODO this is just a random trajectory, you need to do this yourself
total_time=4.
trajs = maketraj(q0, qe, total_time)
tcur = 0.
while tcur < total_time:
rununtil(controllaw, DT, sim, robot, trajs, tcur, cube)
tcur += DT