-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/interior_point_example (pull request #686)
add IPM legged robot example Approved-by: Farbod Farshidian
- Loading branch information
Showing
13 changed files
with
548 additions
and
17 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
312 changes: 312 additions & 0 deletions
312
ocs2_robotic_examples/ocs2_legged_robot/config/multiplot/friction_cone.xml
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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
50 changes: 50 additions & 0 deletions
50
ocs2_robotic_examples/ocs2_legged_robot_ros/launch/legged_robot_ipm.launch
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,50 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<launch> | ||
<!-- visualization config --> | ||
<arg name="rviz" default="true" /> | ||
<arg name="description_name" default="legged_robot_description"/> | ||
<arg name="multiplot" default="false"/> | ||
|
||
<!-- The task file for the mpc. --> | ||
<arg name="taskFile" default="$(find ocs2_legged_robot)/config/mpc/task.info"/> | ||
<!-- The reference related config file of the robot --> | ||
<arg name="referenceFile" default="$(find ocs2_legged_robot)/config/command/reference.info"/> | ||
<!-- The URDF model of the robot --> | ||
<arg name="urdfFile" default="$(find ocs2_robotic_assets)/resources/anymal_c/urdf/anymal.urdf"/> | ||
<!-- The file defining gait definition --> | ||
<arg name="gaitCommandFile" default="$(find ocs2_legged_robot)/config/command/gait.info"/> | ||
|
||
<!-- rviz --> | ||
<group if="$(arg rviz)"> | ||
<param name="$(arg description_name)" textfile="$(arg urdfFile)"/> | ||
<arg name="rvizconfig" default="$(find ocs2_legged_robot_ros)/rviz/legged_robot.rviz" /> | ||
<node pkg="rviz" type="rviz" name="rviz" args="-d $(arg rvizconfig)" output="screen" /> | ||
</group> | ||
|
||
<!-- multiplot --> | ||
<group if="$(arg multiplot)"> | ||
<include file="$(find ocs2_legged_robot_ros)/launch/multiplot.launch"> | ||
<arg name="metrics_config" value="$(find ocs2_legged_robot)/config/multiplot/friction_cone.xml" /> | ||
</include> | ||
</group> | ||
|
||
<!-- make the files into global parameters --> | ||
<param name="multiplot" value="$(arg multiplot)"/> | ||
<param name="taskFile" value="$(arg taskFile)" /> | ||
<param name="referenceFile" value="$(arg referenceFile)" /> | ||
<param name="urdfFile" value="$(arg urdfFile)" /> | ||
<param name="gaitCommandFile" value="$(arg gaitCommandFile)"/> | ||
|
||
<node pkg="ocs2_legged_robot_ros" type="legged_robot_ipm_mpc" name="legged_robot_ipm_mpc" | ||
output="screen" launch-prefix=""/> | ||
|
||
<node pkg="ocs2_legged_robot_ros" type="legged_robot_dummy" name="legged_robot_dummy" | ||
output="screen" launch-prefix="gnome-terminal --"/> | ||
|
||
<node pkg="ocs2_legged_robot_ros" type="legged_robot_target" name="legged_robot_target" | ||
output="screen" launch-prefix="gnome-terminal --"/> | ||
|
||
<node pkg="ocs2_legged_robot_ros" type="legged_robot_gait_command" name="legged_robot_gait_command" | ||
output="screen" launch-prefix="gnome-terminal --"/> | ||
</launch> |
2 changes: 1 addition & 1 deletion
2
ocs2_robotic_examples/ocs2_legged_robot_ros/launch/multiplot.launch
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
96 changes: 96 additions & 0 deletions
96
ocs2_robotic_examples/ocs2_legged_robot_ros/src/LeggedRobotIpmMpcNode.cpp
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,96 @@ | ||
/****************************************************************************** | ||
Copyright (c) 2017, Farbod Farshidian. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************************************************************/ | ||
|
||
#include <ros/init.h> | ||
#include <ros/package.h> | ||
|
||
#include <ocs2_ipm/IpmMpc.h> | ||
#include <ocs2_legged_robot/LeggedRobotInterface.h> | ||
#include <ocs2_ros_interfaces/mpc/MPC_ROS_Interface.h> | ||
#include <ocs2_ros_interfaces/synchronized_module/RosReferenceManager.h> | ||
#include <ocs2_ros_interfaces/synchronized_module/SolverObserverRosCallbacks.h> | ||
|
||
#include "ocs2_legged_robot_ros/gait/GaitReceiver.h" | ||
|
||
using namespace ocs2; | ||
using namespace legged_robot; | ||
|
||
int main(int argc, char** argv) { | ||
const std::string robotName = "legged_robot"; | ||
|
||
// Initialize ros node | ||
::ros::init(argc, argv, robotName + "_mpc"); | ||
::ros::NodeHandle nodeHandle; | ||
// Get node parameters | ||
bool multiplot = false; | ||
std::string taskFile, urdfFile, referenceFile; | ||
nodeHandle.getParam("/multiplot", multiplot); | ||
nodeHandle.getParam("/taskFile", taskFile); | ||
nodeHandle.getParam("/urdfFile", urdfFile); | ||
nodeHandle.getParam("/referenceFile", referenceFile); | ||
|
||
// Robot interface | ||
constexpr bool useHardFrictionConeConstraint = true; | ||
LeggedRobotInterface interface(taskFile, urdfFile, referenceFile, useHardFrictionConeConstraint); | ||
|
||
// Gait receiver | ||
auto gaitReceiverPtr = | ||
std::make_shared<GaitReceiver>(nodeHandle, interface.getSwitchedModelReferenceManagerPtr()->getGaitSchedule(), robotName); | ||
|
||
// ROS ReferenceManager | ||
auto rosReferenceManagerPtr = std::make_shared<RosReferenceManager>(robotName, interface.getReferenceManagerPtr()); | ||
rosReferenceManagerPtr->subscribe(nodeHandle); | ||
|
||
// MPC | ||
IpmMpc mpc(interface.mpcSettings(), interface.ipmSettings(), interface.getOptimalControlProblem(), interface.getInitializer()); | ||
mpc.getSolverPtr()->setReferenceManager(rosReferenceManagerPtr); | ||
mpc.getSolverPtr()->addSynchronizedModule(gaitReceiverPtr); | ||
|
||
// observer for friction cone constraints (only add this for debugging as it slows down the solver) | ||
if (multiplot) { | ||
auto createStateInputBoundsObserver = [&](const std::string& termName) { | ||
const ocs2::scalar_array_t observingTimePoints{0.0}; | ||
const std::vector<std::string> topicNames{"metrics/" + termName + "/0MsLookAhead"}; | ||
auto callback = ocs2::ros::createConstraintCallback(nodeHandle, {0.0}, topicNames, | ||
ocs2::ros::CallbackInterpolationStrategy::linear_interpolation); | ||
return ocs2::SolverObserver::ConstraintTermObserver(ocs2::SolverObserver::Type::Intermediate, termName, std::move(callback)); | ||
}; | ||
for (size_t i = 0; i < interface.getCentroidalModelInfo().numThreeDofContacts; i++) { | ||
const std::string& footName = interface.modelSettings().contactNames3DoF[i]; | ||
mpc.getSolverPtr()->addSolverObserver(createStateInputBoundsObserver(footName + "_frictionCone")); | ||
} | ||
} | ||
|
||
// Launch MPC ROS node | ||
MPC_ROS_Interface mpcNode(mpc, robotName); | ||
mpcNode.launchNodes(nodeHandle); | ||
|
||
// Successful exit | ||
return 0; | ||
} |