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

Feature/mpc specific simulation setup #531

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cd4ca7c
Re-starting to make MPC specific simulation setups.
Beomyeong Dec 13, 2024
59dc4b5
- Adding AvatarMPCControllerThread and MPCHighLevelHumanoidController…
Beomyeong Dec 13, 2024
3d26c5b
- Adding MPCHumanoidHighLevelControlManager
Beomyeong Dec 13, 2024
b5b8977
Just changing variable name
Beomyeong Dec 13, 2024
ec78e2a
- Adding MPCHighLevelControllerState and changing mentioned class name
Beomyeong Dec 13, 2024
868d94e
- Adding WBCC thread and wbcc highlevel manager
Beomyeong Dec 13, 2024
09ad56d
- Adding MPCControllerTask
Beomyeong Dec 13, 2024
e4e5a54
- Adding MPC estimatorthreadFactory and task
Beomyeong Dec 13, 2024
51ef8b1
- Adding wholebodycontrollercoretask.
Beomyeong Dec 13, 2024
c092e3d
- Adding HumanoidRobotMPCContextData and its factory
Beomyeong Dec 13, 2024
50a7cd6
- Adding MPCBarrierScheduledRobotController and MPCHumanoidRobotContr…
Beomyeong Dec 13, 2024
7797f4c
- WholeBodyControllerCoreThread is triggered so that the HumanoidWhol…
Beomyeong Dec 13, 2024
6e870db
- Adding MPCCrossRobotCommandResolver which has CrossRobotCommandReso…
Beomyeong Dec 13, 2024
1ba48ec
- HumanoidRobotMPCContext includes the mpcControlOutputDataList.
Beomyeong Dec 13, 2024
a721ab0
Including desiredMPCControllerOutputDataHolder into constructors of e…
Beomyeong Dec 13, 2024
e0645c5
Merge branch 'develop' into feature/MPC-specific-simulationsetup
Beomyeong Dec 13, 2024
c4b24fa
- MPCControllerOutput is saved into mpcControllerOutputDataHolder in …
Beomyeong Dec 14, 2024
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
32 changes: 13 additions & 19 deletions atlas/src/main/java/us/ihmc/atlas/AtlasRobotModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
import com.jme3.math.Transform;
import us.ihmc.atlas.diagnostic.AtlasDiagnosticParameters;
import us.ihmc.atlas.initialSetup.AtlasSimInitialSetup;
import us.ihmc.atlas.parameters.AtlasCoPTrajectoryParameters;
import us.ihmc.atlas.parameters.AtlasContactPointParameters;
import us.ihmc.atlas.parameters.AtlasFootstepPlannerParameters;
import us.ihmc.atlas.parameters.AtlasHighLevelControllerParameters;
import us.ihmc.atlas.parameters.AtlasICPSplitFractionCalculatorParameters;
import us.ihmc.atlas.parameters.AtlasKinematicsCollisionModel;
import us.ihmc.atlas.parameters.AtlasPhysicalProperties;
import us.ihmc.atlas.parameters.AtlasSensorInformation;
import us.ihmc.atlas.parameters.AtlasSimulationCollisionModel;
import us.ihmc.atlas.parameters.AtlasStateEstimatorParameters;
import us.ihmc.atlas.parameters.AtlasSwingPlannerParameters;
import us.ihmc.atlas.parameters.AtlasVisibilityGraphParameters;
import us.ihmc.atlas.parameters.AtlasWalkingControllerParameters;
import us.ihmc.atlas.parameters.*;
import us.ihmc.atlas.ros.AtlasPPSTimestampOffsetProvider;
import us.ihmc.atlas.sensors.AtlasCollisionBoxProvider;
import us.ihmc.atlas.sensors.AtlasSensorSuiteManager;
Expand Down Expand Up @@ -243,10 +231,10 @@ public RobotDefinition createRobotDefinition(MaterialDefinition materialDefiniti
RobotDefinitionTools.setDefaultMaterial(robotDefinition, new MaterialDefinition(ColorDefinitions.Black()));

getRobotDefinitionMutator().accept(robotDefinition);

if (isUseHandMutatorCollisions())
getRobotDefinitionHandMutator().accept(robotDefinition);

return robotDefinition;
}

Expand Down Expand Up @@ -283,15 +271,14 @@ public Consumer<RobotDefinition> getRobotDefinitionMutator()
robotDefinitionMutator = new AtlasRobotDefinitionMutator(getJointMap(), getSensorInformation());
return robotDefinitionMutator;
}

public Consumer<RobotDefinition> getRobotDefinitionHandMutator()
{
if (robotDefinitionHandMutator == null)
robotDefinitionHandMutator = new AtlasRobotDefinitionHandMutator();
return robotDefinitionHandMutator;
}


@Override
public HighLevelControllerParameters getHighLevelControllerParameters()
{
Expand Down Expand Up @@ -428,8 +415,9 @@ private FullHumanoidRobotModel doArmJointRestriction(FullHumanoidRobotModel full
}
else
{
System.out.println(this.getClass().getName() + ", createFullRobotModel(): range not large enough to reduce for side="
+ robotSide.getLowerCaseName() + " joint=" + armJointName.getCamelCaseNameForStartOfExpression());
System.out.println(
this.getClass().getName() + ", createFullRobotModel(): range not large enough to reduce for side=" + robotSide.getLowerCaseName()
+ " joint=" + armJointName.getCamelCaseNameForStartOfExpression());
}
}
}
Expand Down Expand Up @@ -466,6 +454,12 @@ public double getControllerDT()
return CONTROL_DT;
}

@Override
public double getWBCCDT()
{
return 0.0;
}

@Override
public RobotROSClockCalculator getROSClockCalculator()
{
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package us.ihmc.avatar;

import us.ihmc.avatar.drcRobot.DRCRobotModel;
import us.ihmc.commonWalkingControlModules.barrierScheduler.context.*;
import us.ihmc.commonWalkingControlModules.controllerCore.command.lowLevel.LowLevelOneDoFJointDesiredDataHolder;
import us.ihmc.commonWalkingControlModules.desiredFootStep.footstepGenerator.FootstepValidityIndicator;
import us.ihmc.commonWalkingControlModules.highLevelHumanoidControl.plugin.HumanoidSteppingPlugin;
import us.ihmc.commonWalkingControlModules.highLevelHumanoidControl.plugin.HumanoidSteppingPluginFactory;
import us.ihmc.commonWalkingControlModules.highLevelHumanoidControl.plugin.StepGeneratorCommandInputManager;
import us.ihmc.commons.Conversions;
import us.ihmc.communication.controllerAPI.CommandInputManager;
import us.ihmc.communication.controllerAPI.StatusMessageOutputManager;
import us.ihmc.graphicsDescription.yoGraphics.YoGraphicsListRegistry;
import us.ihmc.graphicsDescription.yoGraphics.plotting.ArtifactList;
import us.ihmc.humanoidRobotics.frames.HumanoidReferenceFrames;
import us.ihmc.humanoidRobotics.model.CenterOfPressureDataHolder;
import us.ihmc.robotModels.FullHumanoidRobotModel;
import us.ihmc.robotics.sensors.CenterOfMassDataHolder;
import us.ihmc.robotics.sensors.ForceSensorDataHolder;
import us.ihmc.ros2.RealtimeROS2Node;
import us.ihmc.scs2.definition.yoGraphic.YoGraphicGroupDefinition;
import us.ihmc.sensorProcessing.model.RobotMotionStatusHolder;
import us.ihmc.sensorProcessing.simulatedSensors.SensorDataContext;
import us.ihmc.wholeBodyController.parameters.ParameterLoaderHelper;
import us.ihmc.yoVariables.registry.YoRegistry;
import us.ihmc.yoVariables.variable.YoBoolean;
import us.ihmc.yoVariables.variable.YoDouble;
import us.ihmc.yoVariables.variable.YoLong;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class AvatarMPCStepGeneratorThread implements AvatarControllerThreadInterface
{
private final YoRegistry csgRegistry = new YoRegistry("csgRegistry");
private final YoGraphicsListRegistry csgGraphics = new YoGraphicsListRegistry();

private final HumanoidSteppingPlugin continuousStepGeneratorPlugin;
private final FullHumanoidRobotModel fullRobotModel;

private final HumanoidRobotMPCContextData humanoidRobotMPCContextData;
private final HumanoidReferenceFrames humanoidReferenceFrames;
private final YoBoolean firstTick = new YoBoolean("FirstTick", csgRegistry);
private final YoLong timestampOffset = new YoLong("TimestampOffsetCSG", csgRegistry);
private final YoDouble csgTime = new YoDouble("csgTime", csgRegistry);
private final YoLong timestamp = new YoLong("TimestampCSG", csgRegistry);
private final YoBoolean runCSG = new YoBoolean("RunCSG", csgRegistry);

private final StepGeneratorCommandInputManager csgCommandInputManager;

public AvatarMPCStepGeneratorThread(HumanoidSteppingPluginFactory pluginFactory,
HumanoidRobotMPCContextDataFactory contextDataFactory,
StatusMessageOutputManager walkingOutputManager,
CommandInputManager walkingCommandInputManager,
DRCRobotModel drcRobotModel,
HumanoidSteppingPluginEnvironmentalConstraints environmentalConstraints,
RealtimeROS2Node ros2Node)
{
this.fullRobotModel = drcRobotModel.createFullRobotModel();

HumanoidRobotContextJointData processedJointData = new HumanoidRobotContextJointData(fullRobotModel.getOneDoFJoints().length);
ForceSensorDataHolder forceSensorDataHolderForController = new ForceSensorDataHolder(Arrays.asList(fullRobotModel.getForceSensorDefinitions()));
CenterOfMassDataHolder centerOfMassDataHolderForController = new CenterOfMassDataHolder();
CenterOfPressureDataHolder centerOfPressureDataHolderForEstimator = new CenterOfPressureDataHolder(fullRobotModel);
LowLevelOneDoFJointDesiredDataHolder desiredJointDataHolder = new LowLevelOneDoFJointDesiredDataHolder(fullRobotModel.getControllableOneDoFJoints());
LowLevelOneDoFJointDesiredDataHolder desiredMPCControlOutputDataHolder = new LowLevelOneDoFJointDesiredDataHolder(fullRobotModel.getControllableOneDoFJoints());
RobotMotionStatusHolder robotMotionStatusHolder = new RobotMotionStatusHolder();
contextDataFactory.setForceSensorDataHolder(forceSensorDataHolderForController);
contextDataFactory.setCenterOfMassDataHolder(centerOfMassDataHolderForController);
contextDataFactory.setCenterOfPressureDataHolder(centerOfPressureDataHolderForEstimator);
contextDataFactory.setRobotMotionStatusHolder(robotMotionStatusHolder);
contextDataFactory.setJointDesiredOutputList(desiredJointDataHolder);
contextDataFactory.setMpcControllerDesiredOutputList(desiredMPCControlOutputDataHolder);
contextDataFactory.setProcessedJointData(processedJointData);
contextDataFactory.setSensorDataContext(new SensorDataContext(fullRobotModel));
humanoidRobotMPCContextData = contextDataFactory.createHumanoidRobotMPCContextData();

csgCommandInputManager = pluginFactory.getStepGeneratorCommandInputManager();

if (environmentalConstraints != null)
{
// sets up the environmental constraint manager as a planar region consumer in the input manager
pluginFactory.addPlanarRegionsListCommandConsumer(environmentalConstraints);
// Adds functions that adjust the footholds based on the environment.
pluginFactory.setFootStepPlanAdjustment(environmentalConstraints.getFootstepPlanAdjustment());
// Adds checkers for footholds based on the environment
for (FootstepValidityIndicator footstepValidityIndicator : environmentalConstraints.getFootstepValidityIndicators())
pluginFactory.addFootstepValidityIndicator(footstepValidityIndicator);

// clear the environment at the beginning of every update
pluginFactory.addUpdatable(environmentalConstraints);
}

// create the callback listeners for the planar regions in the stepping plugin
if (ros2Node != null)
pluginFactory.createStepGeneratorNetworkSubscriber(drcRobotModel.getSimpleRobotName(), ros2Node);

humanoidReferenceFrames = new HumanoidReferenceFrames(fullRobotModel);
continuousStepGeneratorPlugin = pluginFactory.buildPlugin(humanoidReferenceFrames,
drcRobotModel.getStepGeneratorDT(),
drcRobotModel.getWalkingControllerParameters(),
walkingOutputManager,
walkingCommandInputManager,
null,
null,
csgTime);
csgRegistry.addChild(continuousStepGeneratorPlugin.getRegistry());

if (environmentalConstraints != null)
{
csgRegistry.addChild(environmentalConstraints.getRegistry());
csgGraphics.registerYoGraphicsLists(environmentalConstraints.getGraphicsListRegistry().getYoGraphicsLists());

List<ArtifactList> artifactLists = new ArrayList<>();
environmentalConstraints.getGraphicsListRegistry().getRegisteredArtifactLists(artifactLists);
csgGraphics.registerArtifactLists(artifactLists);
}

ParameterLoaderHelper.loadParameters(this, drcRobotModel, csgRegistry);
}

public void initialize()
{
firstTick.set(true);
humanoidRobotMPCContextData.setControllerRan(false);
humanoidRobotMPCContextData.setEstimatorRan(false);
humanoidRobotMPCContextData.setWholeBodyControllerCoreRan(false);
}

private void runOnFirstTick()
{
}

@Override
public void run()
{
runCSG.set(humanoidRobotMPCContextData.getEstimatorRan());
if (!runCSG.getValue())
{
return;
}

try
{
HumanoidRobotContextTools.updateRobot(fullRobotModel, humanoidRobotMPCContextData.getProcessedJointData());
humanoidReferenceFrames.updateFrames();

timestamp.set(humanoidRobotMPCContextData.getTimestamp());
if (firstTick.getValue())
{
// Record this to have time start at 0.0 on the real robot for viewing pleasure.
timestampOffset.set(timestamp.getValue());
}
csgTime.set(Conversions.nanosecondsToSeconds(timestamp.getValue() - timestampOffset.getValue()));

if (firstTick.getValue())
{
runOnFirstTick();
firstTick.set(false);
}

continuousStepGeneratorPlugin.update(csgTime.getValue());
humanoidRobotMPCContextData.setPerceptionRan(true);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

@Override
public YoRegistry getYoVariableRegistry()
{
return csgRegistry;
}

public YoGraphicsListRegistry getSCS1YoGraphicsListRegistry()
{
return csgGraphics;
}

@Override
public YoGraphicGroupDefinition getSCS2YoGraphics()
{
YoGraphicGroupDefinition group = new YoGraphicGroupDefinition(getClass().getSimpleName());
group.addChild(continuousStepGeneratorPlugin.getSCS2YoGraphics());
return group.isEmpty() ? null : group;
}

@Override
public FullHumanoidRobotModel getFullRobotModel()
{
return fullRobotModel;
}

public HumanoidRobotContextData getHumanoidRobotContextData()
{
return humanoidRobotMPCContextData;
}

public StepGeneratorCommandInputManager getCsgCommandInputManager()
{
return csgCommandInputManager;
}
}
Loading
Loading