constraint_impl.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_IMPL_H
00019 #define COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_IMPL_H
00020 
00021 #include <sstream>
00022 #include <set>
00023 #include <vector>
00024 #include <string>
00025 #include <ros/ros.h>
00026 
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/pointer_cast.hpp>
00029 
00030 #include <kdl/chainjnttojacsolver.hpp>
00031 
00032 #include "cob_twist_controller/constraints/constraint.h"
00033 #include "cob_twist_controller/constraints/constraint_params.h"
00034 
00035 /* BEGIN ConstraintsBuilder *************************************************************************************/
00039 template <typename PRIO>
00040 std::set<ConstraintBase_t> ConstraintsBuilder<PRIO>::createConstraints(const TwistControllerParams& tc_params,
00041                                                                        const LimiterParams& limiter_params,
00042                                                                        KDL::ChainJntToJacSolver& jnt_to_jac,
00043                                                                        KDL::ChainFkSolverVel_recursive& fk_solver_vel,
00044                                                                        CallbackDataMediator& data_mediator)
00045 {
00046     std::set<ConstraintBase_t> constraints;
00047     // Joint limit avoidance part
00048     if (JLA_ON == tc_params.constraint_jla)
00049     {
00050         typedef JointLimitAvoidance<ConstraintParamsJLA, PRIO> Jla_t;
00051 
00052         ConstraintParamsJLA params = ConstraintParamsJLA(tc_params.constraint_params.at(JLA), limiter_params);
00053         uint32_t startPrio = params.params_.priority;
00054         for (uint32_t i = 0; i < tc_params.joints.size(); ++i)
00055         {
00056             // TODO: take care PRIO could be of different type than UINT32
00057             params.joint_ = tc_params.joints[i];
00058             params.joint_idx_ = static_cast<int32_t>(i);
00059             boost::shared_ptr<Jla_t > jla(new Jla_t(startPrio++, params, data_mediator));
00060             constraints.insert(boost::static_pointer_cast<PriorityBase<PRIO> >(jla));
00061         }
00062     }
00063     else if (JLA_MID_ON == tc_params.constraint_jla)
00064     {
00065         typedef JointLimitAvoidanceMid<ConstraintParamsJLA, PRIO> JlaMid_t;
00066 
00067         ConstraintParamsJLA params = ConstraintParamsJLA(tc_params.constraint_params.at(JLA), limiter_params);
00068         // TODO: take care PRIO could be of different type than UINT32
00069         boost::shared_ptr<JlaMid_t > jla(new JlaMid_t(params.params_.priority, params, data_mediator));
00070         constraints.insert(boost::static_pointer_cast<PriorityBase<PRIO> >(jla));
00071     }
00072     else if (JLA_INEQ_ON == tc_params.constraint_jla)
00073     {
00074         typedef JointLimitAvoidanceIneq<ConstraintParamsJLA, PRIO> Jla_t;
00075 
00076         ConstraintParamsJLA params = ConstraintParamsJLA(tc_params.constraint_params.at(JLA), limiter_params);
00077         uint32_t startPrio = params.params_.priority;
00078         for (uint32_t i = 0; i < tc_params.joints.size(); ++i)
00079         {
00080             // TODO: take care PRIO could be of different type than UINT32
00081             params.joint_ = tc_params.joints[i];
00082             params.joint_idx_ = static_cast<int32_t>(i);
00083             boost::shared_ptr<Jla_t > jla(new Jla_t(startPrio++, params, data_mediator));
00084             constraints.insert(boost::static_pointer_cast<PriorityBase<PRIO> >(jla));
00085         }
00086     }
00087     else
00088     {
00089         // JLA_OFF selected.
00090     }
00091 
00092     // Collision avoidance part
00093     if (CA_ON == tc_params.constraint_ca)
00094     {
00095         typedef CollisionAvoidance<ConstraintParamsCA, PRIO> CollisionAvoidance_t;
00096         uint32_t startPrio = tc_params.constraint_params.at(CA).priority;
00097 
00098         for (std::vector<std::string>::const_iterator it = tc_params.collision_check_links.begin();
00099              it != tc_params.collision_check_links.end(); it++)
00100         {
00101             ConstraintParamsCA params = ConstraintParamsCA(tc_params.constraint_params.at(CA),tc_params.frame_names, *it);
00102             data_mediator.fill(params);
00103             // TODO: take care PRIO could be of different type than UINT32
00104             boost::shared_ptr<CollisionAvoidance_t > ca(new CollisionAvoidance_t(startPrio--, params, data_mediator, jnt_to_jac, fk_solver_vel));
00105             constraints.insert(boost::static_pointer_cast<PriorityBase<PRIO> >(ca));
00106         }
00107     }
00108     else
00109     {
00110         // CA_OFF selected.
00111     }
00112 
00113     return constraints;
00114 }
00115 /* END ConstraintsBuilder *******************************************************************************************/
00116 
00117 // Collision Avoidance Constraint Implementation
00118 #include "cob_twist_controller/constraints/constraint_ca_impl.h"
00119 
00120 // Joint Limit Avoidance Constraint Implementation
00121 #include "cob_twist_controller/constraints/constraint_jla_impl.h"
00122 
00123 #endif  // COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_IMPL_H


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26