Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Visualstates-ros2 in development branch #137

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
cmake_minimum_required(VERSION 2.8)
project(visualstates)
cmake_minimum_required(VERSION 3.5)
project(visualstatesros2)

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

catkin_python_setup()
catkin_package(INCLUDE_DIRS include)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wunused-parameter)
endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(Qt5 REQUIRED Widgets)

#include_directories(include/visualstates_INCLUDE_DIRS)

SET(SOURCE_CPP_RUNTIME
src/visualstates/codegen/cpp/state.cpp
Expand All @@ -13,23 +26,50 @@ SET(SOURCE_CPP_RUNTIME
src/visualstates/codegen/cpp/runtimegui.cpp
)

include_directories(
${catkin_INCLUDE_DIRS}
include
)
SET(HEADERS include/visualstates/conditionaltransition.h
include/visualstates/runtimegui.h
include/visualstates/state.h
include/visualstates/temporaltransition.h
include/visualstates/test.h
include/visualstates/transition.h
)
include_directories(${rclcpp_INCLUDE_DIRS} ${std_msgs_INCLUDE_DIRS})

#include_directories(include/visualstates/conditionaltransition.h
# include/visualstates/runtimegui.h
# include/visualstates/state.h
# include/visualstates/temporaltransition.h
# include/visualstates/test.h
# )


ADD_LIBRARY(visualStatesRunTime SHARED ${SOURCE_CPP_RUNTIME})

TARGET_LINK_LIBRARIES(visualStatesRunTime pthread)
INSTALL(TARGETS visualStatesRunTime LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

catkin_install_python(PROGRAMS scripts/main.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
#check_if_required
#ament_target_dependencies(visualStatesRunTime "rclcpp" "std_msgs" )

INSTALL(TARGETS visualStatesRunTime LIBRARY DESTINATION lib)

INSTALL(PROGRAMS scripts/main.py DESTINATION bin)

install(
DIRECTORY include/visualstates
DESTINATION lib/${PROJECT_NAME}
)

#install runtime headers
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/visualstates/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
DESTINATION bin)

# install cpp sources for ros node generation
# install cpp sources for ros2 node generation
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/visualstates/codegen/cpp/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/codegen)
DESTINATION bin/codegen)

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION bin)

install(FILES ${HEADERS} DESTINATION bin)

ament_package()

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
9 changes: 6 additions & 3 deletions include/visualstates/runtimegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
#ifndef RUNTIMEGUI_H
#define RUNTIMEGUI_H

#include <ros/ros.h>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"


class RunTimeGui {
protected:
ros::NodeHandle nh;
ros::Publisher runningStatePublisher;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr runningStatePublisher;
//ros::NodeHandle nh;
//ros::Publisher runningStatePublisher;

public:
RunTimeGui();
Expand Down
4 changes: 0 additions & 4 deletions include/visualstates/temporaltransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
Authors : Okan Asik ([email protected])

*/
#ifndef TEMPORALTRANSITION_H
#define TEMPORALTRANSITION_H

#include "transition.h"

class TemporalTransition : public Transition {
Expand All @@ -38,4 +35,3 @@ class TemporalTransition : public Transition {
};


#endif
2 changes: 1 addition & 1 deletion include/visualstates/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "conditionaltransition.h"
#include "interfaces.h"

#include <jderobot/motors.h>
#include </opt/jderobot/include/jderobot/motors.h>

class State0 : public State {
public:
Expand Down
40 changes: 27 additions & 13 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<?xml version="1.0" ?>
<package>
<name>visualstates</name>
<version>0.2.2</version>
<package format="2">
<name>visualstatesros2</name>
<version>1.0.0</version>
<description>The VisualStates is reactive hierarchical visual robot planning tool.</description>
<maintainer email="[email protected]">Okan Aşık</maintainer>
<license>GPLv3</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>


<build_depend>rclcpp</build_depend>
<build_depend>rclpy</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>std_msgs</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>python-rospkg</run_depend>
<run_depend>python-qt5-bindings</run_depend>
<run_depend>python-qt5-bindings-qsci</run_depend>
<export/>
<build_depend>rosidl_default_generators</build_depend>


<exec_depend>rclcpp</exec_depend>
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>

<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>python-ros2pkg</exec_depend>

<exec_depend>python-qt5-bindings</exec_depend>
<exec_depend>python-qt5-bindings-qsci</exec_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
2 changes: 1 addition & 1 deletion scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
from visualstates.gui.visualstates import VisualStates
from visualstates.configs.rospackage import getPackagePath
from visualstates.configs.ros2package import getPackagePath

if __name__ == '__main__':
app = QApplication(sys.argv)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
from ament_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
scripts=['scripts/main.py'],
Expand Down
20 changes: 14 additions & 6 deletions src/visualstates/codegen/cpp/runtimegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@
Authors : Okan Asik ([email protected])

*/
#include <visualstates/runtimegui.h>

#include "../../../../include/visualstates/runtimegui.h"
#include <sstream>
#include <std_msgs/String.h>
#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;


RunTimeGui::RunTimeGui() {
runningStatePublisher = nh.advertise<std_msgs::String>("/runtime_gui", 100);
rclcpp::Node::SharedPtr node;
runningStatePublisher = node->create_publisher<std_msgs::msg::String>("/runtime_gui", 100);

//runningStatePublisher = node->advertise<std_msgs::msg::String>("/runtime_gui", 100);
}

void RunTimeGui::emitRunningStateById(int id) {
std_msgs::String runningStateMsg;
//std_msgs::msg::String runningStateMsg;
auto runningStateMsg = std::make_shared<std_msgs::msg::String>();
std::stringstream ss;
ss << id;
runningStateMsg.data = ss.str();
runningStatePublisher.publish(runningStateMsg);
runningStateMsg->data = ss.str();
runningStatePublisher->publish(runningStateMsg);
}

void RunTimeGui::emitLoadFromRoot() {
Expand Down
10 changes: 1 addition & 9 deletions src/visualstates/codegen/cpp/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Authors : Okan Asik ([email protected])

*/
#include <visualstates/state.h>
#include "../../../../include/visualstates/state.h"
#include <unistd.h>
#include <sys/time.h>
#include <iostream>
Expand Down Expand Up @@ -45,14 +45,6 @@ void State::init() {
gui->emitRunningStateById(id);
}

// re-set the initial state as the current state
for (unsigned int i = 0; i < states.size(); i++) {
if (states.at(i)->initial) {
currentState = states.at(i);
break;
}
}

if (currentState != NULL) {
currentState->init();
}
Expand Down
2 changes: 1 addition & 1 deletion src/visualstates/codegen/cpp/temporaltransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Authors : Okan Asik ([email protected])

*/
#include <visualstates/temporaltransition.h>
#include "../../../../include/visualstates/temporaltransition.h"
#include <sys/time.h>

TemporalTransition::TemporalTransition(int id, int destinationId, int elapsedTime):
Expand Down
4 changes: 2 additions & 2 deletions src/visualstates/codegen/cpp/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
Authors : Okan Asik ([email protected])

*/
#include <visualstates/test.h>
#include "../../../../include/visualstates/test.h"
#include <iostream>
#include <easyiceconfig/EasyIce.h>
//#include <easyiceconfig/EasyIce.h>
#include <string>
#include <visualstates/runtimegui.h>

Expand Down
2 changes: 1 addition & 1 deletion src/visualstates/codegen/cpp/transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Authors : Okan Asik ([email protected])

*/
#include <visualstates/transition.h>
#include "../../../../include/visualstates/transition.h"

Transition::Transition(int id, int destinationId) {
this->id = id;
Expand Down
2 changes: 1 addition & 1 deletion src/visualstates/codegen/python/runtimegui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from visualstates.gui.tree.treemodel import TreeModel
from visualstates.core.state import State
from visualstates.core.transition import Transition
from visualstates.configs.rospackage import getPackagePath
from visualstates.configs.ros2package import getPackagePath


class RunTimeGui(QMainWindow):
Expand Down
6 changes: 1 addition & 5 deletions src/visualstates/codegen/python/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def init(self):
if self.gui is not None:
self.gui.emitRunningStateById(self.id)

# reset the currentState as the initial state
for state in self.states:
if state.initial:
self.currentState = state
break
# also init children
if self.currentState is not None:
self.currentState.init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

'''

from visualstates.generators.pythonrosgenerator import PythonRosGenerator
from visualstates.generators.pythonros2generator import PythonRos2Generator

class RosConfig(object):
class Ros2Config(object):

PUBLISH = 'Publish'
SUBSCRIBE = 'Subscribe'
Expand All @@ -30,7 +30,7 @@ def __init__(self):
self.buildDependencies = []
self.runDependencies = []

def updateROSConfig(self, newConfig):
def updateROS2Config(self, newConfig):
self.updateTopics(newConfig.topics)
self.updateBuildDependencies(newConfig.buildDependencies)
self.updateRunDependencies(newConfig.runDependencies)
Expand All @@ -48,9 +48,9 @@ def isTopicByName(self, topicName):
def addTopic(self, id, topic):
newTopic = {}
newTopic['id'] = id
if topic['opType'] == RosConfig.PUBLISH:
if topic['opType'] == Ros2Config.PUBLISH:
newTopic['methodname'] = topic['methodname']
elif topic['opType'] == RosConfig.SUBSCRIBE:
elif topic['opType'] == Ros2Config.SUBSCRIBE:
newTopic['variablename'] = topic['variablename']
newTopic['name'] = topic['name']
newTopic['type'] = topic['type']
Expand Down Expand Up @@ -115,11 +115,11 @@ def createNode(self, doc):
for t in self.topics:
tElement = doc.createElement('topic')
tElement.setAttribute('id', str(t['id']))
if t['opType'] == RosConfig.PUBLISH:
if t['opType'] == Ros2Config.PUBLISH:
methodElement = doc.createElement('methodname')
methodElement.appendChild(doc.createTextNode(t['methodname']))
tElement.appendChild(methodElement)
elif t['opType'] == RosConfig.SUBSCRIBE:
elif t['opType'] == Ros2Config.SUBSCRIBE:
varElement = doc.createElement('variablename')
varElement.appendChild(doc.createTextNode(t['variablename']))
tElement.appendChild(varElement)
Expand Down Expand Up @@ -162,13 +162,13 @@ def loadNode(self, node):
topic['name'] = t.getElementsByTagName('name')[0].childNodes[0].nodeValue
topic['type'] = t.getElementsByTagName('type')[0].childNodes[0].nodeValue
topic['opType'] = t.getElementsByTagName('opType')[0].childNodes[0].nodeValue
if topic['opType'] == RosConfig.PUBLISH:
if topic['opType'] == Ros2Config.PUBLISH:
methodnames = t.getElementsByTagName('methodname')
if len(methodnames) > 0:
topic['methodname'] = methodnames[0].childNodes[0].nodeValue
else:
topic['methodname'] = self.getVarName(topic['name'])
elif topic['opType'] == RosConfig.SUBSCRIBE:
elif topic['opType'] == Ros2Config.SUBSCRIBE:
varnames = t.getElementsByTagName('variablename')
if len(varnames) > 0:
topic['variablename'] = varnames[0].childNodes[0].nodeValue
Expand Down
Loading