/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* Author(s): Grace Chrysilla Created on: 2017-07-18 (C) Copyright 2013-2017 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #include // #include #include #include #if CISST_HAS_JSON #include #endif CMN_IMPLEMENT_SERVICES_DERIVED(mtsPSMCompensation, mtsTaskPeriodic); mtsPSMCompensation::mtsPSMCompensation(const std::string & componentName, double periodInSeconds): mtsTaskPeriodic(componentName, periodInSeconds, false, 500) { StateTable.AddData(mJointStateEncoder, "JointStateEncoder"); StateTable.AddData(mJointStateCompensated, "CorrectedJointState"); SetupInterfaces(); } void mtsPSMCompensation::SetupInterfaces(void){ // add provided interfaces mtsInterfaceProvided * interfaceProvided = AddInterfaceProvided("JointStateCorrected"); if (!interfaceProvided){ CMN_LOG_CLASS_INIT_ERROR << "failed to add \"JointStateCorrected\" to component \"" << this->GetName() << "\"" << std::endl; return; } // get the latest values from both the state tables for comparison interfaceProvided->AddCommandReadState(StateTable, mJointStateCompensated, "GetJointState"); // add another provided interfaces interfaceProvided = AddInterfaceProvided("JointStateEncoder"); if (!interfaceProvided){ CMN_LOG_CLASS_INIT_ERROR << "failed to add \"JointStateEncoder\" to component \"" << this->GetName() << "\"" << std::endl; return; } // get the latest values from both the state tables for comparison interfaceProvided->AddCommandReadState(StateTable, mJointStateEncoder, "GetJointState"); // add required interfaces mtsInterfaceRequired * interfaceRequired = AddInterfaceRequired("PID"); if (!interfaceRequired){ CMN_LOG_CLASS_INIT_ERROR << "failed to add \"PSM-RO\" to component \"" << this->GetName() << "\"" << std::endl; return; } // add commands to the interface interfaceRequired->AddFunction("GetJointState", this->GetJointState); } void mtsPSMCompensation::Configure(const std::string & filename) { #if CISST_HAS_JSON std::ifstream jsonStream; jsonStream.open(filename.c_str()); Json::Value jsonConfig, jsonValue; Json::Reader jsonReader; if (!jsonReader.parse(jsonStream, jsonConfig)) { CMN_LOG_CLASS_INIT_ERROR << "Configure: failed to parse configuration" << std::endl << "File: " << filename << std::endl << "Error(s):" << std::endl << jsonReader.getFormattedErrorMessages(); return; } // search for array of parameters const Json::Value parameters = jsonConfig["parameters"]; if (parameters.size() == 0) { CMN_LOG_CLASS_INIT_ERROR << "Configure: configuration files needs \"parameters\"" << std::endl; return; } for (unsigned int i=0; i