11 #include "hrpsys/util/VectorConvert.h" 13 #include <hrpModel/ModelLoaderUtil.h> 16 #include <hrpModel/Sensor.h> 24 "implementation_id",
"KalmanFilter",
25 "type_name",
"KalmanFilter",
26 "description",
"kalman filter",
27 "version", HRPSYS_PACKAGE_VERSION,
29 "category",
"example",
30 "activity_type",
"DataFlowComponent",
33 "lang_type",
"compile",
35 "conf.default.debugLevel",
"0",
43 m_rateIn(
"rate", m_rate),
44 m_accIn(
"acc", m_acc),
45 m_accRefIn(
"accRef", m_accRef),
46 m_rpyIn(
"rpyIn", m_rate),
47 m_qCurrentIn(
"qCurrent", m_qCurrent),
48 m_rpyOut(
"rpy", m_rpy),
49 m_rpyRawOut(
"rpy_raw", m_rpyRaw),
50 m_baseRpyCurrentOut(
"baseRpyCurrent", m_baseRpyCurrent),
51 m_KalmanFilterServicePort(
"KalmanFilterService"),
66 #define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 ) 69 std::cerr <<
"[" <<
m_profile.instance_name <<
"] onInitialize()" << std::endl;
103 std::cerr <<
"[" <<
m_profile.instance_name <<
"]failed to get dt" << std::endl;
104 return RTC::RTC_ERROR;
110 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
111 int comPos = nameServer.find(
",");
113 comPos = nameServer.length();
115 nameServer = nameServer.substr(0, comPos);
118 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
120 std::cerr <<
"[" <<
m_profile.instance_name <<
"]failed to load model[" << prop[
"model"] <<
"]" << std::endl;
136 kf_algorithm = OpenHRP::KalmanFilterService::RPYKalmanFilter;
169 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onActivated(" << ec_id <<
")" << std::endl;
175 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onDeactivated(" << ec_id <<
")" << std::endl;
198 for (
int i = 0;
i <
m_robot->numJoints();
i++ ){
202 double sx_ref = 0.0, sy_ref = 0.0, sz_ref = 0.0;
215 std::cerr <<
"[" <<
m_profile.instance_name <<
"] raw data acc : " << std::endl << acc << std::endl;
216 std::cerr <<
"[" <<
m_profile.instance_name <<
"] raw data gyro : " << std::endl << gyro << std::endl;
218 hrp::Vector3 rpy, rpyRaw, baseRpyCurrent;
219 if (
kf_algorithm == OpenHRP::KalmanFilterService::QuaternionExtendedKalmanFilter) {
221 }
else if (
kf_algorithm == OpenHRP::KalmanFilterService::RPYKalmanFilter) {
224 m_robot->calcForwardKinematics();
231 BtoS = (
m_robot->rootLink()->R).transpose();
233 rpy_kf.
main_one(rpy, rpyRaw, baseRpyCurrent, acc, gyro, sl_y, BtoS);
238 m_rpy.data.r = rpy(0);
239 m_rpy.data.p = rpy(1);
240 m_rpy.data.y = rpy(2);
293 std::cerr <<
"[" <<
m_profile.instance_name <<
"] setKalmanFilterParam" << std::endl;
296 for (
size_t i = 0;
i < 3;
i++) {
300 for (
size_t i = 0;
i < 3;
i++) {
301 rpyoff(
i) = i_param.sensorRPY_offset[
i];
304 std::cerr <<
"[" <<
m_profile.instance_name <<
"] kf_algorithm=" << (
kf_algorithm==OpenHRP::KalmanFilterService::RPYKalmanFilter?
"RPYKalmanFilter":
"QuaternionExtendedKalmanFilter") << std::endl;
305 std::cerr <<
"[" <<
m_profile.instance_name <<
"] acc_offset = " <<
acc_offset.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
" [",
"]")) << std::endl;
306 std::cerr <<
"[" <<
m_profile.instance_name <<
"] sensorRPY_offset = " << rpyoff.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
" [",
"]")) << std::endl;
322 for (
size_t i = 0;
i < 3;
i++) {
326 for (
size_t i = 0;
i < 3;
i++) {
327 i_param.sensorRPY_offset[
i] = rpyoff(
i);
339 RTC::Create<KalmanFilter>,
340 RTC::Delete<KalmanFilter>);
ComponentProfile m_profile
void setdt(const double _dt)
png_infop png_charpp int png_charpp profile
unsigned int m_debugLevel
void resetKalmanFilterState()
TimedAcceleration3D m_acc
bool resetKalmanFilterState()
virtual RTC::ReturnCode_t onInitialize()
virtual ReturnCode_t initialize()
bool stringTo(To &val, const char *str)
OutPort< TimedOrientation3D > m_rpyOut
OpenHRP::KalmanFilterService::KFAlgorithm kf_algorithm
RTC::InPort< RTC::TimedDoubleSeq > m_qCurrentIn
void main_one(hrp::Vector3 &rpy, hrp::Vector3 &rpyRaw, const hrp::Vector3 &acc, const hrp::Vector3 &gyro)
RTC::OutPort< RTC::TimedOrientation3D > m_baseRpyCurrentOut
TimedOrientation3D m_rpyRaw
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
OutPort< TimedOrientation3D > m_rpyRawOut
coil::Properties & getProperties()
static Manager & instance()
void setSensorR(const hrp::Matrix33 &sr)
bool getKalmanFilterParam(OpenHRP::KalmanFilterService::KalmanFilterParam &i_param)
bool addOutPort(const char *name, OutPortBase &outport)
InPort< TimedAcceleration3D > m_accIn
boost::shared_ptr< Body > BodyPtr
virtual ~KalmanFilter()
Destructor.
RTC::TimedDoubleSeq m_qCurrent
InPort< TimedAngularVelocity3D > m_rpyIn
Matrix33 rotFromRpy(const Vector3 &rpy)
void setParam(const double _dt, const double _Q_angle, const double _Q_rate, const double _R_angle, const std::string print_str="")
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
coil::Properties & getConfig()
KalmanFilterService_impl m_service0
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
void resetKalmanFilterState()
RTC::TimedOrientation3D m_baseRpyCurrent
TimedAcceleration3D m_accRef
void main_one(hrp::Vector3 &rpy, hrp::Vector3 &rpyRaw, hrp::Vector3 &baseRpyCurrent, const hrp::Vector3 &acc, const hrp::Vector3 &gyro, const double &sl_y, const hrp::Matrix33 &BtoS)
void kalman(KalmanFilter *i_kalman)
bool setKalmanFilterParam(const OpenHRP::KalmanFilterService::KalmanFilterParam &i_param)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
static const char * kalmanfilter_spec[]
InPort< TimedAcceleration3D > m_accRefIn
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
bool addPort(PortBase &port)
virtual bool write(DataType &value)
bool addInPort(const char *name, InPortBase &inport)
TimedAngularVelocity3D m_rate
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
RTC::CorbaPort m_KalmanFilterServicePort
InPort< TimedAngularVelocity3D > m_rateIn
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
KalmanFilter(RTC::Manager *manager)
Constructor.
void KalmanFilterInit(RTC::Manager *manager)
hrp::Matrix33 sensorR_offset