hrpEC-art.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include <iostream>
00003 #include "hrpEC.h"
00004 #include <rtm/ECFactory.h>
00005 #include "hrpsys/io/iob.h"
00006 #include <linux/art_task.h>
00007 
00008 namespace RTC
00009 {
00010     hrpExecutionContext::hrpExecutionContext()
00011         : PeriodicExecutionContext(), 
00012           m_priority(ART_PRIO_MAX-1)
00013     {
00014         resetProfile();
00015         rtclog.setName("hrpEC");
00016         coil::Properties& prop(Manager::instance().getConfig());
00017         
00018         // Priority
00019         getProperty(prop, "exec_cxt.periodic.priority", m_priority);
00020         getProperty(prop, "exec_cxt.periodic.art.priority", m_priority);
00021         RTC_DEBUG(("Priority: %d", m_priority));
00022     }
00023 
00024     bool hrpExecutionContext::waitForNextPeriod()
00025     {
00026         int nsubstep = number_of_substeps();
00027         while(1){
00028             if (art_wait() == -1){
00029                 perror("art_wait");
00030                 return false;
00031             }
00032             if (read_iob_frame() % nsubstep == 0) break;
00033         }
00034         return true;
00035     }
00036     bool hrpExecutionContext::enterRT()
00037     {
00038         unsigned long period_usec 
00039             = (m_period.sec()*1e6+m_period.usec())/number_of_substeps();
00040         if (art_enter(m_priority, ART_TASK_PERIODIC, period_usec) == -1){
00041             perror("art_enter");
00042             return false;
00043         }
00044         return true;
00045     }
00046     bool hrpExecutionContext::exitRT()
00047     {
00048         if (art_exit() == -1){
00049             perror("art_exit");
00050             return false;
00051         }
00052         return true;
00053     }
00054 };
00055 
00056 
00057 extern "C"
00058 {
00059     void hrpECInit(RTC::Manager* manager)
00060     {
00061         manager->registerECFactory("hrpExecutionContext",
00062                                    RTC::ECCreate<RTC::hrpExecutionContext>,
00063                                    RTC::ECDelete<RTC::hrpExecutionContext>);
00064         std::cerr << "hrpExecutionContext for ART is registered" << std::endl;
00065     }
00066 };
00067  


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:55