00001 /* 00002 * Software License Agreement (Apache License) 00003 * 00004 * Copyright (c) 2013, Southwest Research Institute 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #include "constrained_ik/constraint_group.h" 00020 #include "constrained_ik/constrained_ik.h" 00021 #include <ros/ros.h> 00022 00023 namespace constrained_ik 00024 { 00025 00026 using namespace Eigen; 00027 00028 // initialize limits/tolerances to default values 00029 ConstraintGroup::ConstraintGroup() : Constraint() 00030 { 00031 } 00032 00033 void ConstraintGroup::add(Constraint* constraint) 00034 { 00035 if (initialized_) 00036 constraint->init(ik_); 00037 00038 constraints_.push_back(constraint); 00039 } 00040 00041 Eigen::VectorXd ConstraintGroup::calcError() 00042 { 00043 VectorXd error; 00044 for (size_t i=0; i<constraints_.size(); ++i) 00045 constraints_[i].updateError(error); 00046 00047 return error; 00048 } 00049 00050 // translate task-space errors into joint-space errors 00051 Eigen::MatrixXd ConstraintGroup::calcJacobian() 00052 { 00053 MatrixXd jacobian; 00054 for (size_t i=0; i<constraints_.size(); ++i) 00055 constraints_[i].updateJacobian(jacobian); 00056 00057 return jacobian; 00058 } 00059 00060 bool ConstraintGroup::checkStatus() const 00061 { 00062 bool done=true; 00063 00064 for (size_t i=0; i<constraints_.size(); ++i) 00065 done &= constraints_[i].checkStatus(); 00066 00067 if (done) return done; 00068 00069 return Constraint::checkStatus(); 00070 } 00071 00072 void ConstraintGroup::init(const Constrained_IK* ik) 00073 { 00074 Constraint::init(ik); 00075 00076 for (size_t i=0; i<constraints_.size(); ++i) 00077 constraints_[i].init(ik); 00078 } 00079 00080 void ConstraintGroup::reset() 00081 { 00082 Constraint::reset(); 00083 00084 for (size_t i=0; i<constraints_.size(); ++i) 00085 constraints_[i].reset(); 00086 } 00087 00088 void ConstraintGroup::update(const SolverState &state) 00089 { 00090 Constraint::update(state); 00091 00092 for (size_t i=0; i<constraints_.size(); ++i) 00093 constraints_[i].update(state); 00094 } 00095 00096 } // namespace constrained_ik 00097