|
From: <vij...@us...> - 2009-01-15 02:31:26
|
Revision: 9471
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=9471&view=rev
Author: vijaypradeep
Date: 2009-01-15 01:32:18 +0000 (Thu, 15 Jan 2009)
Log Message:
-----------
Started prototyping a realtime scheduling framework
Added Paths:
-----------
pkg/trunk/sandbox/
pkg/trunk/sandbox/rt_scheduler/
pkg/trunk/sandbox/rt_scheduler/CMakeLists.txt
pkg/trunk/sandbox/rt_scheduler/Makefile
pkg/trunk/sandbox/rt_scheduler/include/
pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/
pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/oracle.h
pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/ports.h
pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/rt_node.h
pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/scheduler.h
pkg/trunk/sandbox/rt_scheduler/manifest.xml
pkg/trunk/sandbox/rt_scheduler/src/
pkg/trunk/sandbox/rt_scheduler/src/run_test.cpp
Added: pkg/trunk/sandbox/rt_scheduler/CMakeLists.txt
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/CMakeLists.txt (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/CMakeLists.txt 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+rospack(rt_scheduler)
+
+#rospack_add_library(rt_scheduler )
+
+rospack_add_executable(run_test src/run_test.cpp)
+#target_link_libraries(run_test rt_scheduler)
+
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
\ No newline at end of file
Added: pkg/trunk/sandbox/rt_scheduler/Makefile
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/Makefile (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/Makefile 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
Added: pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/oracle.h
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/oracle.h (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/oracle.h 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,81 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+//! \author Vijay Pradeep
+
+#ifndef RT_SCHEDULER_ORACLE_H_
+#define RT_SCHEDULER_ORACLE_H_
+
+#include <vector>
+#include <utility>
+#include <string>
+
+#include "rt_scheduler/rt_node.h"
+#include "rt_scheduler/ports.h"
+
+namespace rt_scheduler
+{
+
+class Oracle
+{
+public:
+ Oracle()
+ { }
+
+ ~Oracle()
+ { }
+
+ void registerPort(OutputPort<int>* port, const std::string& name)
+ {
+ std::pair< std::string, OutputPort<int>* > entry(name, port) ;
+ ports_.push_back(entry) ;
+ }
+
+ void find(OutputPort<int>* &port, const std::string& name)
+ {
+ port = NULL ;
+ for (unsigned int i=0; i < ports_.size(); i++)
+ {
+ if (ports_[i].first == name)
+ port = ports_[i].second ;
+ }
+ }
+
+private:
+ std::vector< std::pair<std::string, OutputPort<int>* > > ports_ ;
+} ;
+
+}
+
+#endif /* RT_SCHEDULER_ORACLE_H_ */
Added: pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/ports.h
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/ports.h (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/ports.h 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,94 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+//! \author Vijay Pradeep
+
+#ifndef RT_SCHEDULER_PORTS_H_
+#define RT_SCHEDULER_PORTS_H_
+
+#include "rt_scheduler/rt_node.h"
+
+namespace rt_scheduler
+{
+
+template<class T>
+class OutputPort
+{
+public:
+ OutputPort(RtNode* owner) { owner_ = owner ; }
+
+//private
+ T data_ ;
+ RtNode* owner_ ;
+} ;
+
+template<class T>
+class InputPort
+{
+public:
+ InputPort(RtNode* owner)
+ {
+ owner_ = owner ;
+ output_port_ = NULL ;
+ id_ = owner_->generateID() ;
+ }
+
+ bool getData(T& data)
+ {
+ if (output_port_)
+ {
+ data = output_port_->data_ ;
+ return true ;
+ }
+ else
+ return false ;
+ }
+
+ void Link(OutputPort<T>* output_port)
+ {
+ output_port_ = output_port ;
+ owner_->updateDep(id_, output_port_->owner_) ;
+ }
+
+//private
+ OutputPort<T>* output_port_ ;
+ RtNode* owner_ ;
+ unsigned int id_ ;
+} ;
+
+}
+
+
+
+#endif /* RT_SCHEDULER_PORTS_H_ */
Added: pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/rt_node.h
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/rt_node.h (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/rt_node.h 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,80 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+//! \author Vijay Pradeep
+
+#ifndef RT_SCHEDULER_RT_NODE_H_
+#define RT_SCHEDULER_RT_NODE_H_
+
+#include <string>
+#include <vector>
+#include <utility>
+
+namespace rt_scheduler
+{
+
+class RtNode
+{
+public:
+ RtNode() { }
+ RtNode(std::string name) : name_(name) { } ;
+ virtual ~RtNode() { } ;
+ virtual bool update() = 0 ;
+
+ unsigned int generateID()
+ {
+ unsigned int next_id = deps_.size() ;
+ deps_.push_back(NULL) ;
+ printf("%s: Adding port ID #%u\n", name_.c_str(), next_id) ;
+ return next_id ;
+ }
+
+ void updateDep(unsigned int id, RtNode* dep_node)
+ {
+ deps_[id] = dep_node ;
+ }
+
+ std::string name_ ;
+
+//private:
+ std::vector< RtNode* > deps_ ;
+ std::vector<unsigned int> exec_order_ ;
+
+} ;
+
+}
+
+
+
+#endif /* RT_SCHEDULER_RT_NODE_H_ */
Added: pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/scheduler.h
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/scheduler.h (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/include/rt_scheduler/scheduler.h 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,101 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+//! \author Vijay Pradeep
+
+#ifndef RT_SCHEDULER_SCHEDULER_H_
+#define RT_SCHEDULER_SCHEDULER_H_
+
+
+
+#include <vector>
+
+#include "rt_scheduler/rt_node.h"
+
+
+
+namespace rt_scheduler
+{
+
+class Scheduler : public rt_scheduler::RtNode
+{
+public:
+ Scheduler()
+ { }
+
+ ~Scheduler()
+ { }
+
+ void add(RtNode* node)
+ {
+ node_list_.push_back(node) ;
+ printf("Adding %s to scheduler\n", node->name_.c_str()) ;
+ }
+
+ bool update()
+ {
+ bool success = true ;
+ for (unsigned int i=0; i < exec_order_.size(); i++)
+ {
+ printf("Updating Node #%u: %s\n", exec_order_[i], node_list_[exec_order_[i]]->name_.c_str()) ;
+ success = success && node_list_[exec_order_[i]]->update() ;
+ }
+ return success ;
+ }
+
+ // A super dumb, dangerous scheduler
+ void updateExecutionOrder()
+ {
+ printf("Dependencies:\n") ;
+ for (unsigned int i=0; i<node_list_.size(); i++)
+ {
+ for (unsigned int j=0; j<node_list_[i]->deps_.size(); j++)
+ printf(" %s -> %s\n", node_list_[i]->name_.c_str(), node_list_[i]->deps_[j]->name_.c_str()) ;
+ }
+
+
+ exec_order_.resize(node_list_.size()) ;
+ for (unsigned int i=0; i<exec_order_.size(); i++)
+ exec_order_[i] = i ;
+ }
+
+private:
+ std::vector<RtNode*> node_list_ ;
+ std::vector<unsigned int> exec_order_ ;
+
+} ;
+
+}
+
+#endif /* RT_SCHEDULER_SCHEDULER_H_ */
Added: pkg/trunk/sandbox/rt_scheduler/manifest.xml
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/manifest.xml (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/manifest.xml 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,6 @@
+<package>
+ <description>Vijay's prototype idea of a reatime (single thread) scheduler</description>
+ <author>Vijay Pradeep</author>
+ <license>BSD</license>
+ <review status="Experimental" notes=""/>
+</package>
Added: pkg/trunk/sandbox/rt_scheduler/src/run_test.cpp
===================================================================
--- pkg/trunk/sandbox/rt_scheduler/src/run_test.cpp (rev 0)
+++ pkg/trunk/sandbox/rt_scheduler/src/run_test.cpp 2009-01-15 01:32:18 UTC (rev 9471)
@@ -0,0 +1,188 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+//! \author Vijay Pradeep
+
+#include <cstdio>
+
+#include "rt_scheduler/rt_node.h"
+#include "rt_scheduler/ports.h"
+#include "rt_scheduler/scheduler.h"
+#include "rt_scheduler/oracle.h"
+using namespace rt_scheduler ;
+
+class Talker : public rt_scheduler::RtNode
+{
+public:
+ Talker(int start, int inc) : out_(this)
+ {
+ state_ = start ;
+ inc_ = inc ;
+ }
+
+ ~Talker()
+ { }
+
+ bool update()
+ {
+ state_ += inc_ ;
+ out_.data_ = state_ ;
+ printf("%s: out = %i\n", name_.c_str(), out_.data_) ;
+ return true ;
+ }
+
+ OutputPort<int> out_ ;
+ int state_ ;
+ int inc_ ;
+} ;
+
+class Adder : public rt_scheduler::RtNode
+{
+public:
+ Adder(Oracle& oracle, std::string name) : rt_scheduler::RtNode(name), in_A_(this),
+ in_B_(this), out_(this)
+ {
+ oracle.registerPort(&out_, name+"/out") ;
+ }
+
+ ~Adder()
+ { }
+
+ bool update()
+ {
+ int a,b ;
+ if (in_A_.getData(a))
+ printf(" Got data from Port A: %i\n", a) ;
+ else
+ {
+ printf(" Error accessing Port A\n") ;
+ return false ;
+ }
+ if (in_B_.getData(b))
+ printf(" Got data from Port B: %i\n", b) ;
+ else
+ {
+ printf(" Error accessing Port B\n") ;
+ return false ;
+ }
+
+ int result = a+b ;
+
+ out_.data_ = result ;
+
+ printf(" Result: %i\n", result) ;
+
+ return true ;
+ }
+
+ InputPort<int> in_A_ ;
+ InputPort<int> in_B_ ;
+ OutputPort<int> out_ ;
+} ;
+
+class Doubler : public rt_scheduler::RtNode
+{
+public:
+ Doubler(std::string name) : rt_scheduler::RtNode(name), in_(this)
+ {
+
+ }
+
+ ~Doubler()
+ { }
+
+ bool update()
+ {
+ int a ;
+ if (in_.getData(a))
+ printf(" Got data from Port: %i\n", a) ;
+ else
+ {
+ printf(" Error accessing Port\n") ;
+ return false ;
+ }
+
+ int result = 2*a ;
+
+
+ printf(" Result: %i\n", result) ;
+
+ return true ;
+ }
+
+ InputPort<int> in_ ;
+} ;
+
+
+int main(int argc, char** argv)
+{
+ // Initialize
+ Oracle oracle ;
+
+ Talker talker_A(5,2) ;
+ Talker talker_B(10,-1) ;
+ Adder adder(oracle, "Adder") ;
+ Doubler doubler("Doubler") ;
+
+ talker_A.name_ = "TalkerA" ;
+ talker_B.name_ = "TalkerB" ;
+
+ // Connect ports together
+ adder.in_A_.Link(&talker_A.out_) ;
+ adder.in_B_.Link(&talker_B.out_) ;
+
+ OutputPort<int>* port ;
+ oracle.find(port, "Adder/out") ;
+ if(port != NULL)
+ doubler.in_.Link(port) ;
+ else
+ printf("Oracle could not find port") ;
+
+ // Add to the scheduler
+ Scheduler scheduler ;
+ scheduler.add(&talker_A) ;
+ scheduler.add(&talker_B) ;
+ scheduler.add(&adder) ;
+ scheduler.add(&doubler) ;
+
+ scheduler.updateExecutionOrder() ;
+
+ while(true)
+ {
+ scheduler.update() ;
+ getchar() ;
+ }
+
+ return 0 ;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|