From ccf39ccd0428f30e8e9a9dfea19caedc6484851a Mon Sep 17 00:00:00 2001
From: Manfred Kroehnert <Manfred.Kroehnert@kit.edu>
Date: Tue, 9 Sep 2014 16:15:37 +0200
Subject: [PATCH] initial skeleton for MotionControlTest statechart

The intention of this statechart is to contain all MotionControl states
to make them testable in a common scenario.
The scenario should contain a Gui and the startup of all required
components and make the single MotionControl States executable/selectable
via Gui buttons.
---
 .../MotionControlGroup/CMakeLists.txt         |  2 +
 .../MotionControlGroup.scgxml                 |  1 +
 .../testing/MotionControlTest.cpp             | 83 +++++++++++++++++++
 .../testing/MotionControlTest.h               | 58 +++++++++++++
 .../testing/MotionControlTest.xml             | 34 ++++++++
 5 files changed, 178 insertions(+)
 create mode 100644 source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.cpp
 create mode 100644 source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.h
 create mode 100644 source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.xml

diff --git a/source/RobotAPI/statecharts/MotionControlGroup/CMakeLists.txt b/source/RobotAPI/statecharts/MotionControlGroup/CMakeLists.txt
index 63722b666..1206cb89a 100644
--- a/source/RobotAPI/statecharts/MotionControlGroup/CMakeLists.txt
+++ b/source/RobotAPI/statecharts/MotionControlGroup/CMakeLists.txt
@@ -21,6 +21,7 @@ MotionControlGroupRemoteStateOfferer.cpp
 ./MoveJoints.cpp
 testing/testMoveJoints.cpp
 ./StopRobot.cpp
+testing/MotionControlTest.cpp
 #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp
 )
 
@@ -29,6 +30,7 @@ MotionControlGroupRemoteStateOfferer.h
 ./MoveJoints.h
 testing/testMoveJoints.h
 ./StopRobot.h
+testing/MotionControlTest.h
 #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h
 )
 
diff --git a/source/RobotAPI/statecharts/MotionControlGroup/MotionControlGroup.scgxml b/source/RobotAPI/statecharts/MotionControlGroup/MotionControlGroup.scgxml
index 5bb6eae95..624d0bb5a 100644
--- a/source/RobotAPI/statecharts/MotionControlGroup/MotionControlGroup.scgxml
+++ b/source/RobotAPI/statecharts/MotionControlGroup/MotionControlGroup.scgxml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <StatechartGroup name="MotionControlGroup" package="RobotAPI">
 	<Folder basename="testing">
+		<State filename="MotionControlTest.xml"/>
 		<State filename="testMoveJoints.xml"/>
 	</Folder>
 	<State filename="MoveJoints.xml" visibility="public"/>
diff --git a/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.cpp b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.cpp
new file mode 100644
index 000000000..45ae85719
--- /dev/null
+++ b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.cpp
@@ -0,0 +1,83 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::MotionControlGroup
+ * @author     Manfred Kroehnert ( Manfred dot Kroehnert at kit dot edu )
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#include "MotionControlTest.h"
+
+using namespace armarx;
+using namespace MotionControlGroup;
+
+// DO NOT EDIT NEXT LINE
+MotionControlTest::SubClassRegistry MotionControlTest::Registry(MotionControlTest::GetName(), &MotionControlTest::CreateInstance);
+
+
+
+MotionControlTest::MotionControlTest(XMLStateConstructorParams stateData) :
+    XMLStateTemplate < MotionControlTest > (stateData)
+{
+}
+
+void MotionControlTest::onEnter()
+{
+    // put your user code for the enter-point here
+    // execution time should be short (<100ms)
+}
+
+void MotionControlTest::run()
+{
+    // put your user code for the execution-phase here
+    // runs in seperate thread, thus can do complex operations
+    // should check constantly whether isRunningTaskStopped() returns true
+
+
+    while (!isRunningTaskStopped()) // stop run function if returning true
+    {
+        // do your calculations
+    }
+
+}
+
+void MotionControlTest::onBreak()
+{
+    // put your user code for the breaking point here
+    // execution time should be short (<100ms)
+}
+
+void MotionControlTest::onExit()
+{
+    // put your user code for the exit point here
+    // execution time should be short (<100ms)
+
+}
+
+// DO NOT EDIT NEXT FUNCTION
+std::string MotionControlTest::GetName()
+{
+    return "MotionControlTest";
+}
+
+// DO NOT EDIT NEXT FUNCTION
+XMLStateFactoryBasePtr MotionControlTest::CreateInstance(XMLStateConstructorParams stateData)
+{
+    return XMLStateFactoryBasePtr(new MotionControlTest(stateData));
+}
+
diff --git a/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.h b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.h
new file mode 100644
index 000000000..62f572792
--- /dev/null
+++ b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::MotionControlGroup
+ * @author     Manfred Kroehnert ( Manfred dot Kroehnert at kit dot edu )
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#ifndef _ARMARX_XMLUSERCODE_RobotAPI_MotionControlGroup_MotionControlTest_H
+#define _ARMARX_XMLUSERCODE_RobotAPI_MotionControlGroup_MotionControlTest_H
+
+#include <Core/statechart/xmlstates/XMLState.h>
+
+namespace armarx
+{
+    namespace MotionControlGroup
+    {
+        class MotionControlTest :
+            virtual public XMLStateTemplate < MotionControlTest > ,
+        public XMLStateFactoryBase
+        {
+        public:
+            MotionControlTest(XMLStateConstructorParams stateData);
+
+            // inherited from StateBase
+            void onEnter();
+            void run();
+            void onBreak();
+            void onExit();
+
+            // static functions for AbstractFactory Method
+            static std::string GetName();
+            static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData);
+            static SubClassRegistry Registry;
+
+            // DO NOT INSERT ANY CLASS MEMBERS,
+            // use stateparameters instead,
+            // if classmember are neccessary nonetheless, reset them in onEnter
+        };
+    }
+}
+
+#endif
diff --git a/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.xml b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.xml
new file mode 100644
index 000000000..a495c9c67
--- /dev/null
+++ b/source/RobotAPI/statecharts/MotionControlGroup/testing/MotionControlTest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<State version="1.0" name="MotionControlTest" uuid="244F76B3-ADCC-44EF-8FC0-E4029F7409C9" width="800" height="600">
+	<InputParameters/>
+	<OutputParameters/>
+	<LocalParameters/>
+	<Substates>
+		<EndState name="EvFailure" event="EvFailure" left="673.229" top="345.17" boundingSquareSize="76.5658"/>
+		<EndState name="EvSuccess" event="EvSuccess" left="671.09" top="217.3" boundingSquareSize="75.8092"/>
+		<LocalState name="MoveJoints" refuuid="1A25B687-CFBC-4CA3-A1C7-32EEAF004C45" left="419.489" top="322.048" boundingSquareSize="72.6746"/>
+		<LocalState name="StopRobot" refuuid="A88DB279-17A6-4776-A3C0-114B775609C9" left="417.837" top="242.775" boundingSquareSize="74.0754"/>
+	</Substates>
+	<Events/>
+	<Transitions>
+		<Transition from="StopRobot" to="EvSuccess" eventName="EvSuccess">
+			<ParameterMappings/>
+			<SupportPoints>
+				<SupportPoint posX="701.9" posY="267.548"/>
+			</SupportPoints>
+		</Transition>
+		<Transition from="MoveJoints" to="EvSuccess" eventName="EvJointTargetReached">
+			<ParameterMappings/>
+			<SupportPoints>
+				<SupportPoint posX="687.036" posY="255.987"/>
+			</SupportPoints>
+		</Transition>
+		<Transition from="MoveJoints" to="EvFailure" eventName="EvTimeout">
+			<ParameterMappings/>
+			<SupportPoints>
+				<SupportPoint posX="695.294" posY="383.155"/>
+			</SupportPoints>
+		</Transition>
+	</Transitions>
+</State>
+
-- 
GitLab