This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added elastic joint control for icub
- Loading branch information
1 parent
58184c3
commit b90048d
Showing
12 changed files
with
954 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
function gainsInit = gains(CONFIG) | ||
%GAINS generates initial control gains for both the momentum task | ||
%(primary task in SoT controller) and the postural task. | ||
% | ||
% gains = GAINS(CONFIG) takes as an input the structure CONFIG, which | ||
% contains all the robot configuration parameters. The output is the structure | ||
% gainsInit, which contains the initial gains matrices. | ||
% | ||
% Author : Gabriele Nava (gabriele.nava@iit.it) | ||
% Genova, May 2016 | ||
% | ||
|
||
% ------------Initialization---------------- | ||
% Config parameters | ||
ndof = CONFIG.ndof; | ||
|
||
%% Gains for two feet on ground | ||
if sum(CONFIG.feet_on_ground) == 2 | ||
|
||
% CoM and angular momentum gains | ||
gainsPCoM = diag([40 45 40]); | ||
gainsDCoM = 2*sqrt(gainsPCoM); | ||
gainsPAngMom = diag([1 5 1]); | ||
gainsDAngMom = 2*sqrt(gainsPAngMom); | ||
|
||
% impedances acting in the null space of the desired contact forces | ||
impTorso = [ 20 30 20]; | ||
impArms = [ 10 10 10 5 5]; | ||
impLeftLeg = [ 35 40 10 30 5 10]; | ||
impRightLeg = [ 35 40 10 30 5 10]; | ||
end | ||
|
||
%% Parameters for one foot on ground | ||
if sum(CONFIG.feet_on_ground) == 1 | ||
|
||
% CoM and angular momentum gains | ||
gainsPCoM = diag([30 35 30]); | ||
gainsDCoM = 2*sqrt(gainsPCoM); | ||
gainsPAngMom = diag([2.5 5 2.5]); | ||
gainsDAngMom = 2*sqrt(gainsPAngMom); | ||
|
||
% impedances acting in the null space of the desired contact forces | ||
impTorso = [ 10 15 10]; | ||
impArms = [ 5 5 5 2.5 2.5]; | ||
|
||
if CONFIG.feet_on_ground(1) == 1 | ||
|
||
impLeftLeg = [ 15 15 15 15 5 5]; | ||
impRightLeg = [ 10 10 15 15 5 5]; | ||
else | ||
impLeftLeg = [ 10 10 15 15 5 5]; | ||
impRightLeg = [ 15 15 15 15 5 5]; | ||
end | ||
end | ||
|
||
%% Definition of the impedances and dampings vectors | ||
gainsInit.impedances = [impTorso,impArms,impArms,impLeftLeg,impRightLeg]; | ||
gainsInit.dampings = 2*sqrt(gainsInit.impedances); | ||
|
||
if (size(gainsInit.impedances,2) ~= ndof) | ||
|
||
error('Dimension mismatch between ndof and dimension of the variable impedences. Check these variables in the file gains.m'); | ||
end | ||
|
||
%% Momentum and postural gains | ||
gainsInit.impedances = diag(gainsInit.impedances); | ||
gainsInit.dampings = diag(gainsInit.dampings); | ||
gainsInit.momentumGains = [gainsDCoM zeros(3); zeros(3) gainsDAngMom]; | ||
gainsInit.intMomentumGains = [gainsPCoM zeros(3); zeros(3) gainsPAngMom]; | ||
|
||
% gains for feet correction to avoid numerical intrgration errors | ||
gainsInit.corrPosFeet = 100; | ||
|
||
end |
81 changes: 81 additions & 0 deletions
81
controllers/torqueBalancing_JE/config/trajectoryGenerator.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
function desired_x_dx_ddx_CoM = trajectoryGenerator(xCoMInit,t,CONFIG) | ||
%TRAJECTORYGENERATOR generates a desired CoM trajectory. The default trajectory | ||
% is a sinusoid in the Y direction. | ||
% | ||
% desired_x_dx_ddx_CoM = TRAJECTORYGENERATOR(xCoMInit,t,CONFIG) takes as an | ||
% input the initial CoM position, xCoMInit, the current time t and the structure | ||
% CONFIG which contains the user-defined parameters. | ||
% The output desired_x_dx_ddx_CoM is a matrix [3x3] which contains the CoM | ||
% reference acceleration, velocity and position. | ||
% | ||
% Author : Gabriele Nava (gabriele.nava@iit.it) | ||
% Genova, May 2016 | ||
% | ||
|
||
% ------------Initialization---------------- | ||
% Config parameters | ||
feet_on_ground = CONFIG.feet_on_ground; | ||
demo_movements = CONFIG.demo_movements; | ||
|
||
% Initial parameters | ||
directionOfOscillation = [0;0;0]; | ||
referenceParams = [0.0 0.0]; %referenceParams(1) = amplitude of ascillations in meters | ||
%referenceParams(2) = frequency of ascillations in Hertz | ||
|
||
% NB: IF THE INTEGRATION IS PERFORMED USING ODE15S THIS PARAMETER SHOULD REMAIN ZERO | ||
noOscillationTime = 0; % If params.demo_movements = 1, the variable noOscillationTime is the time, in seconds, | ||
% that the robot waits before starting the left-and-right | ||
|
||
%% Trajectory definition | ||
if demo_movements == 1 | ||
|
||
if sum(feet_on_ground) == 2 | ||
|
||
directionOfOscillation = [0;1;0]; | ||
referenceParams = [0.035 0.35]; | ||
else | ||
|
||
directionOfOscillation = [0;1;0]; | ||
referenceParams = [0.015 0.15]; | ||
end | ||
end | ||
|
||
%% Trajectory generation | ||
frequency = referenceParams(2); | ||
|
||
if size(t,1)==1 && size(t,2)==1 | ||
|
||
if t >= noOscillationTime | ||
|
||
amplitude = referenceParams(1); | ||
else | ||
amplitude = 0; | ||
end | ||
|
||
xCoMDes = xCoMInit + amplitude*sin(2*pi*frequency*t)*directionOfOscillation; | ||
dxCoMDes = amplitude*2*pi*frequency*cos(2*pi*frequency*t)*directionOfOscillation; | ||
ddxCoMDes = - amplitude*(2*pi*frequency)^2*sin(2*pi*frequency*t)*directionOfOscillation; | ||
|
||
desired_x_dx_ddx_CoM = [xCoMDes dxCoMDes ddxCoMDes]; | ||
else | ||
|
||
% in case t is a vector | ||
desired_x_dx_ddx_CoM = zeros(3,3,length(t)); | ||
|
||
for k = 1:length(t) | ||
if t(k) >= noOscillationTime | ||
|
||
amplitude = referenceParams(1); | ||
else | ||
amplitude = 0; | ||
end | ||
|
||
xCoMDes = xCoMInit + amplitude*sin(2*pi*frequency*t(k))*directionOfOscillation; | ||
dxCoMDes = amplitude*2*pi*frequency*cos(2*pi*frequency*t(k))*directionOfOscillation; | ||
ddxCoMDes = - amplitude*(2*pi*frequency)^2*sin(2*pi*frequency*t(k))*directionOfOscillation; | ||
|
||
desired_x_dx_ddx_CoM(:,:,k) = [xCoMDes dxCoMDes ddxCoMDes]; | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
function [] = initForwardDynamics(CONFIG) | ||
%INITFORWARDDYNAMICS configures the forward dynamics integration by setting | ||
% state initial conditions, control gains, etc. | ||
% | ||
% [] = INITFORWARDDYNAMICS(CONFIG) takes as input the structure CONFIG | ||
% containing the initial user-defined parameters. It has no output. The | ||
% forward dynamics integration will be performed following the options | ||
% the user specified in the initialization script. | ||
% | ||
% Author : Gabriele Nava (gabriele.nava@iit.it) | ||
% Genova, May 2016 | ||
% | ||
|
||
% ------------Initialization---------------- | ||
%% Setup the configuration and state parameters | ||
feet_on_ground = CONFIG.feet_on_ground; | ||
ndof = CONFIG.ndof; | ||
qjInit = CONFIG.qjInit; | ||
dqjInit = zeros(ndof,1); | ||
dx_bInit = zeros(3,1); | ||
w_omega_bInit = zeros(3,1); | ||
|
||
% initialize motor state | ||
thetaInit = qjInit; | ||
dthetaInit = dqjInit; | ||
chi_motorInit = [thetaInit;dthetaInit]; | ||
|
||
%% Contact constraints definition | ||
if sum(feet_on_ground) == 2 | ||
|
||
CONFIG.constraintLinkNames = {'l_sole','r_sole'}; | ||
|
||
elseif feet_on_ground(1) == 1 && feet_on_ground(2) == 0 | ||
|
||
CONFIG.constraintLinkNames = {'l_sole'}; | ||
|
||
elseif feet_on_ground(1) == 0 && feet_on_ground(2) == 1 | ||
|
||
CONFIG.constraintLinkNames = {'r_sole'}; | ||
end | ||
|
||
CONFIG.numConstraints = length(CONFIG.constraintLinkNames); | ||
|
||
%% Configure the model using initial conditions | ||
wbm_updateState(qjInit,dqjInit,[dx_bInit;w_omega_bInit]); | ||
|
||
% fixing the world reference frame w.r.t. the foot on ground position | ||
if feet_on_ground(1) == 1 | ||
|
||
[x_bInit,w_R_bInit] = wbm_getWorldFrameFromFixLnk('l_sole',qjInit); | ||
else | ||
[x_bInit,w_R_bInit] = wbm_getWorldFrameFromFixLnk('r_sole',qjInit); | ||
end | ||
|
||
wbm_setWorldFrame(w_R_bInit,x_bInit,[0 0 -9.81]') | ||
|
||
% initial state (floating base + joints) | ||
[basePoseInit,~,~,~] = wbm_getState(); | ||
chi_robotInit = [basePoseInit; qjInit; dx_bInit; w_omega_bInit; dqjInit]; | ||
|
||
%% Initial state that consider also joints elasticity | ||
chiInit = [chi_robotInit; chi_motorInit]; | ||
|
||
%% Initial gains | ||
% the initial gains are defined before the numerical integration | ||
CONFIG.gainsInit = gains(CONFIG); | ||
|
||
%% Initial dynamics and forward kinematics | ||
% initial state | ||
CONFIG.initState = robotState(chi_robotInit,CONFIG); | ||
% initial dynamics | ||
CONFIG.initDynamics = robotDynamics(CONFIG.initState,CONFIG); | ||
% initial forward kinematics | ||
CONFIG.initForKinematics = robotForKinematics(CONFIG.initState,CONFIG.initDynamics); | ||
|
||
%% Forward dynamics integration | ||
CONFIG.wait = waitbar(0,'Forward dynamics integration...'); | ||
forwardDynFunc = @(t,chi)forwardDynamics(t,chi,CONFIG); | ||
|
||
% either fixed step integrator or ODE15s | ||
if CONFIG.integrateWithFixedStep == 1 | ||
[t,chi] = euleroForward(forwardDynFunc,chiInit,CONFIG.tEnd,CONFIG.tStart,CONFIG.sim_step); | ||
else | ||
[t,chi] = ode15s(forwardDynFunc,CONFIG.tStart:CONFIG.sim_step:CONFIG.tEnd,chiInit,CONFIG.options); | ||
end | ||
|
||
delete(CONFIG.wait) | ||
|
||
%% Visualize integration results and robot simulator | ||
CONFIG.figureCont = initVisualizer(t,chi,CONFIG); | ||
|
||
end |
Oops, something went wrong.