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           m_thread_pending (false)
00014     {
00015         resetProfile();
00016         rtclog.setName("hrpEC");
00017         coil::Properties& prop(Manager::instance().getConfig());
00018         
00019         // Priority
00020         getProperty(prop, "exec_cxt.periodic.priority", m_priority);
00021         getProperty(prop, "exec_cxt.periodic.art.priority", m_priority);
00022         RTC_DEBUG(("Priority: %d", m_priority));
00023     }
00024 
00025     bool hrpExecutionContext::waitForNextPeriod()
00026     {
00027         int nsubstep = number_of_substeps();
00028         while(1){
00029             if (art_wait() == -1){
00030                 perror("art_wait");
00031                 return false;
00032             }
00033             if (read_iob_frame() % nsubstep == 0) break;
00034         }
00035         return true;
00036     }
00037     bool hrpExecutionContext::enterRT()
00038     {
00039         unsigned long period_usec 
00040             = (m_period.sec()*1e6+m_period.usec())/number_of_substeps();
00041         if (art_enter(m_priority, ART_TASK_PERIODIC, period_usec) == -1){
00042             perror("art_enter");
00043             return false;
00044         }
00045         return true;
00046     }
00047     bool hrpExecutionContext::exitRT()
00048     {
00049         if (art_exit() == -1){
00050             perror("art_exit");
00051             return false;
00052         }
00053         return true;
00054     }
00055 };
00056 
00057 
00058 extern "C"
00059 {
00060     void hrpECInit(RTC::Manager* manager)
00061     {
00062         manager->registerECFactory("hrpExecutionContext",
00063                                    RTC::ECCreate<RTC::hrpExecutionContext>,
00064                                    RTC::ECDelete<RTC::hrpExecutionContext>);
00065         std::cerr << "hrpExecutionContext for ART is registered" << std::endl;
00066     }
00067 };
00068  


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18