Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the feetYawDelta and the slowWhenBackwardFactor. #89

Merged
merged 7 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/WalkingControllersFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ checkandset_dependency(iDynTree)
find_package(Eigen3 3.2.92 QUIET)
checkandset_dependency(Eigen3)

find_package(UnicyclePlanner 0.3.0 QUIET)
find_package(UnicyclePlanner 0.3.101 QUIET)
checkandset_dependency(UnicyclePlanner)

find_package(osqp QUIET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace WalkingControllers
double m_plannerHorizon; /**< Horizon of the planner. */
std::size_t m_stancePhaseDelay; /**< Delay in ticks of the beginning of the stance phase. */

double m_leftYawDeltaInRad; /**< Offset for the left foot rotation around the z axis. */
double m_rightYawDeltaInRad; /**< Offset for the right foot rotation around the z axis. */
double m_nominalWidth; /**< Nominal width between two feet. */
double m_initTime; /**< Init time of the current trajectory. */

Expand Down
127 changes: 60 additions & 67 deletions src/TrajectoryPlanner/src/TrajectoryGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ bool TrajectoryGenerator::configurePlanner(const yarp::os::Searchable& config)
double timeWeight = config.check("timeWeight", yarp::os::Value(2.5)).asDouble();
double positionWeight = config.check("positionWeight", yarp::os::Value(1.0)).asDouble();
double slowWhenTurningGain = config.check("slowWhenTurningGain", yarp::os::Value(0.0)).asDouble();
double slowWhenBackwardFactor = config.check("slowWhenBackwardFactor", yarp::os::Value(1.0)).asDouble();
double maxStepLength = config.check("maxStepLength", yarp::os::Value(0.05)).asDouble();
double minStepLength = config.check("minStepLength", yarp::os::Value(0.005)).asDouble();
double minWidth = config.check("minWidth", yarp::os::Value(0.03)).asDouble();
Expand All @@ -103,6 +104,8 @@ bool TrajectoryGenerator::configurePlanner(const yarp::os::Searchable& config)
yarp::os::Value(0.4)).asDouble();
double mergePointRatio = config.check("mergePointRatio", yarp::os::Value(0.5)).asDouble();
double lastStepDCMOffset = config.check("lastStepDCMOffset", yarp::os::Value(0.0)).asDouble();
m_leftYawDeltaInRad = iDynTree::deg2rad(config.check("leftYawDeltaInDeg", yarp::os::Value(0.0)).asDouble());
m_rightYawDeltaInRad = iDynTree::deg2rad(config.check("rightYawDeltaInDeg", yarp::os::Value(0.0)).asDouble());

m_nominalWidth = config.check("nominalWidth", yarp::os::Value(0.04)).asDouble();

Expand All @@ -129,6 +132,9 @@ bool TrajectoryGenerator::configurePlanner(const yarp::os::Searchable& config)
ok = ok && unicyclePlanner->setMinimumAngleForNewSteps(minAngleVariation);
ok = ok && unicyclePlanner->setMinimumStepLength(minStepLength);
ok = ok && unicyclePlanner->setSlowWhenTurnGain(slowWhenTurningGain);
ok = ok && unicyclePlanner->setSlowWhenBackwardFactor(slowWhenBackwardFactor);
unicyclePlanner->setLeftFootYawOffsetInRadians(m_leftYawDeltaInRad);
unicyclePlanner->setRightFootYawOffsetInRadians(m_rightYawDeltaInRad);
unicyclePlanner->addTerminalStep(true);
unicyclePlanner->startWithLeft(m_swingLeft);
unicyclePlanner->resetStartingFootIfStill(startWithSameFoot);
Expand Down Expand Up @@ -192,9 +198,10 @@ void TrajectoryGenerator::computeThread()

bool correctLeft;

iDynTree::Vector2 desiredPoint;
iDynTree::Vector2 desiredPointInRelativeFrame, desiredPointInAbsoluteFrame;
iDynTree::Vector2 measuredPositionLeft, measuredPositionRight;
double measuredAngleLeft, measuredAngleRight;
double leftYawDeltaInRad, rightYawDeltaInRad;

iDynTree::Vector2 DCMBoundaryConditionAtMergePointPosition;
iDynTree::Vector2 DCMBoundaryConditionAtMergePointVelocity;
Expand All @@ -217,7 +224,7 @@ void TrajectoryGenerator::computeThread()
endTime = initTime + m_plannerHorizon;

// set desired point
desiredPoint = m_desiredPoint;
desiredPointInRelativeFrame = m_desiredPoint;

// dcm boundary conditions
DCMBoundaryConditionAtMergePointPosition = m_DCMBoundaryConditionAtMergePointPosition;
Expand All @@ -227,11 +234,13 @@ void TrajectoryGenerator::computeThread()
measuredPositionLeft(0) = m_measuredTransformLeft.getPosition()(0);
measuredPositionLeft(1) = m_measuredTransformLeft.getPosition()(1);
measuredAngleLeft = m_measuredTransformLeft.getRotation().asRPY()(2);
leftYawDeltaInRad = m_leftYawDeltaInRad;

// right foot
measuredPositionRight(0) = m_measuredTransformRight.getPosition()(0);
measuredPositionRight(1) = m_measuredTransformRight.getPosition()(1);
measuredAngleRight = m_measuredTransformRight.getRotation().asRPY()(2);
rightYawDeltaInRad = m_rightYawDeltaInRad;

correctLeft = m_correctLeft;

Expand All @@ -246,12 +255,55 @@ void TrajectoryGenerator::computeThread()
}
}

iDynTree::Vector2 measuredPosition;
double measuredAngle;
measuredPosition = correctLeft ? measuredPositionLeft : measuredPositionRight;
measuredAngle = correctLeft ? measuredAngleLeft : measuredAngleRight;

DCMInitialState initialState;
initialState.initialPosition = DCMBoundaryConditionAtMergePointPosition;
initialState.initialVelocity = DCMBoundaryConditionAtMergePointVelocity;

Eigen::Vector2d unicyclePositionFromStanceFoot, footPosition, unicyclePosition;
unicyclePositionFromStanceFoot(0) = 0.0;

Eigen::Matrix2d unicycleRotation;
double unicycleAngle;

if (correctLeft)
{
unicyclePositionFromStanceFoot(1) = -nominalWidth/2;
unicycleAngle = measuredAngleLeft - leftYawDeltaInRad;
footPosition = iDynTree::toEigen(measuredPositionLeft);
}
else
{
unicyclePositionFromStanceFoot(1) = nominalWidth/2;
unicycleAngle = measuredAngleRight - rightYawDeltaInRad;
footPosition = iDynTree::toEigen(measuredPositionRight);
}

double s_theta = std::sin(unicycleAngle);
double c_theta = std::cos(unicycleAngle);

unicycleRotation(0,0) = c_theta;
unicycleRotation(0,1) = -s_theta;
unicycleRotation(1,0) = s_theta;
unicycleRotation(1,1) = c_theta;

unicyclePosition = unicycleRotation * unicyclePositionFromStanceFoot + footPosition;

// apply the homogeneous transformation w_H_{unicycle}
iDynTree::toEigen(desiredPointInAbsoluteFrame) = unicycleRotation * (iDynTree::toEigen(m_referencePointDistance) +
iDynTree::toEigen(desiredPointInRelativeFrame))
+ unicyclePosition;

// clear the old trajectory
std::shared_ptr<UnicyclePlanner> unicyclePlanner = m_trajectoryGenerator.unicyclePlanner();
unicyclePlanner->clearDesiredTrajectory();

// add new point
if(!unicyclePlanner->addDesiredTrajectoryPoint(endTime, desiredPoint))
if(!unicyclePlanner->addDesiredTrajectoryPoint(endTime, desiredPointInAbsoluteFrame))
{
// something goes wrong
std::lock_guard<std::mutex> guard(m_mutex);
Expand All @@ -260,15 +312,6 @@ void TrajectoryGenerator::computeThread()
break;
}

iDynTree::Vector2 measuredPosition;
double measuredAngle;
measuredPosition = correctLeft ? measuredPositionLeft : measuredPositionRight;
measuredAngle = correctLeft ? measuredAngleLeft : measuredAngleRight;

DCMInitialState initialState;
initialState.initialPosition = DCMBoundaryConditionAtMergePointPosition;
initialState.initialVelocity = DCMBoundaryConditionAtMergePointVelocity;

if (!m_dcmGenerator->setDCMInitialState(initialState)) {
// something goes wrong
std::lock_guard<std::mutex> guard(m_mutex);
Expand All @@ -282,35 +325,6 @@ void TrajectoryGenerator::computeThread()
iDynTree::MatrixFixSize<2,2> ellipseImage = freeSpaceEllipse.imageMatrix(), newEllipseImage;
iDynTree::VectorFixSize<2> centerOffset = freeSpaceEllipse.centerOffset(), newCenterOffset;

Eigen::Vector2d unicyclePositionFromStanceFoot, footPosition, unicyclePosition;
unicyclePositionFromStanceFoot(0) = 0.0;

Eigen::Matrix2d unicycleRotation;
double theta;

if (correctLeft)
{
unicyclePositionFromStanceFoot(1) = -nominalWidth/2;
theta = measuredAngleLeft;
footPosition = iDynTree::toEigen(measuredPositionLeft);
}
else
{
unicyclePositionFromStanceFoot(1) = nominalWidth/2;
theta = measuredAngleRight;
footPosition = iDynTree::toEigen(measuredPositionRight);
}

double s_theta = std::sin(theta);
double c_theta = std::cos(theta);

unicycleRotation(0,0) = c_theta;
unicycleRotation(0,1) = -s_theta;
unicycleRotation(1,0) = s_theta;
unicycleRotation(1,1) = c_theta;

unicyclePosition = unicycleRotation * unicyclePositionFromStanceFoot + footPosition;

iDynTree::toEigen(newEllipseImage) = unicycleRotation * iDynTree::toEigen(ellipseImage);

iDynTree::toEigen(newCenterOffset) = unicycleRotation * iDynTree::toEigen(centerOffset) + unicyclePosition;
Expand Down Expand Up @@ -489,7 +503,10 @@ bool TrajectoryGenerator::generateFirstTrajectories(const iDynTree::Transform &l
return false;
}

m_generatorState = GeneratorState::Returned;
{
std::lock_guard<std::mutex> guard(m_mutex);
m_generatorState = GeneratorState::Returned;
}
return true;
}

Expand All @@ -513,32 +530,8 @@ bool TrajectoryGenerator::updateTrajectories(double initTime, const iDynTree::Ve
<< "Please call 'generateFirstTrajectories()' method.";
return false;
}
}
// if correctLeft is true the stance foot is the true.
// The vector (expressed in the unicycle reference frame from the left foot to the center of the
// unicycle is [0, width/2]')
iDynTree::Vector2 unicyclePositionFromStanceFoot;
unicyclePositionFromStanceFoot(0) = 0.0;
unicyclePositionFromStanceFoot(1) = correctLeft ? -m_nominalWidth/2 : m_nominalWidth/2;

iDynTree::Vector2 desredPositionFromStanceFoot;
iDynTree::toEigen(desredPositionFromStanceFoot) = iDynTree::toEigen(unicyclePositionFromStanceFoot)
+ iDynTree::toEigen(m_referencePointDistance) + iDynTree::toEigen(desiredPosition);

// prepare the rotation matrix w_R_{unicycle}
double theta = measured.getRotation().asRPY()(2);
double s_theta = std::sin(theta);
double c_theta = std::cos(theta);

// save the data
{
std::lock_guard<std::mutex> guard(m_mutex);

// apply the homogeneous transformation w_H_{unicycle}
m_desiredPoint(0) = c_theta * desredPositionFromStanceFoot(0)
- s_theta * desredPositionFromStanceFoot(1) + measured.getPosition()(0);
m_desiredPoint(1) = s_theta * desredPositionFromStanceFoot(0)
+ c_theta * desredPositionFromStanceFoot(1) + measured.getPosition()(1);
m_desiredPoint = desiredPosition;

m_initTime = initTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand Down Expand Up @@ -39,6 +40,10 @@ switchOverSwingRatio 0.7
leftZMPDelta (0.03 -0.005)
rightZMPDelta (0.03 0.005)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

# Last Step DCM Offset
# If it is 0.5 the final DCM will be in the middle of the two footsteps;
# If it is 0 the DCM position coincides with the stance foot ZMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand Down Expand Up @@ -39,6 +40,10 @@ switchOverSwingRatio 1.0
leftZMPDelta (-0.015 -0.01)
rightZMPDelta (-0.015 0.01)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

# Last Step DCM Offset
# If it is 0.5 the final DCM will be in the middle of the two footsteps;
# If it is 0 the DCM position coincides with the stance foot ZMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand All @@ -19,7 +20,7 @@ minWidth 0.15
maxAngleVariation 20.0
minAngleVariation 8.0
#Timings
maxStepDuration 0.95
maxStepDuration 0.95
minStepDuration 0.80

##Nominal Values
Expand All @@ -39,6 +40,10 @@ switchOverSwingRatio 0.7
leftZMPDelta (0.03 -0.005)
rightZMPDelta (0.03 0.005)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

# Last Step DCM Offset
# If it is 0.5 the final DCM will be in the middle of the two footsteps;
# If it is 0 the DCM position coincides with the stance foot ZMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand Down Expand Up @@ -39,6 +40,10 @@ switchOverSwingRatio 0.7
leftZMPDelta (0.03 -0.005)
rightZMPDelta (0.03 0.005)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

#MergePoint
mergePointRatio 0.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand Down Expand Up @@ -39,6 +40,10 @@ switchOverSwingRatio 0.7
leftZMPDelta (0.03 -0.005)
rightZMPDelta (0.03 0.005)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

#MergePoint
mergePointRatio 0.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ referencePosition (0.1 0.0)
timeWeight 2.5
positionWeight 1.0
slowWhenTurningGain 5.0
slowWhenBackwardFactor 1.0

##Bounds
#Step length
Expand Down Expand Up @@ -39,6 +40,10 @@ switchOverSwingRatio 0.7
leftZMPDelta (0.03 -0.005)
rightZMPDelta (0.03 0.005)

#Feet cartesian offset on the yaw
leftYawDeltaInDeg 0.0
rightYawDeltaInDeg 0.0

# Last Step DCM Offset
# If it is 0.5 the final DCM will be in the middle of the two footsteps;
# If it is 0 the DCM position coincides with the stance foot ZMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ l_hip_pitch -5000.0 -1500.0 0.0
r_hip_pitch 5000.0 1500.0 0.0
l_hip_roll 25000.0 1000.0 0.0
r_hip_roll -25000.0 -1000.0 0.0
r_hip_yaw 5000.0 2000.0 0.0
l_hip_yaw -5000.0 -2000.0 0.0
r_hip_yaw 10000.0 2000.0 0.0
l_hip_yaw -7000.0 -2000.0 0.0
Loading