Commit 9667ec9b authored by Svetlana's avatar Svetlana

All components communicate over ROS. Scripts to help building and executing all the components.

parent 8e24f5f6
%!/bin/bash
source devel/setup.bash
catkin_make
%!/bin/bash
source devel/setup.bash
xterm -T listener -e rosrun listener listener &
xterm -T publisher -e rosrun publisher publisher &
// %Tag(FULLTEXT)%
#include "ros/ros.h" #include "ros/ros.h"
#include "std_msgs/String.h" #include "std_msgs/Float64MultiArray.h"
// %Tag(CALLBACK)% void chatterCallback(const std_msgs::Float64MultiArray::ConstPtr& msg)
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{ {
ROS_INFO("I heard: [%s]", msg->data.c_str()); ROS_INFO("Received command: %f", msg->data[0]);
} }
// %EndTag(CALLBACK)%
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
...@@ -15,14 +12,8 @@ int main(int argc, char **argv) ...@@ -15,14 +12,8 @@ int main(int argc, char **argv)
ros::NodeHandle n; ros::NodeHandle n;
// %Tag(SUBSCRIBER)% ros::Subscriber sub = n.subscribe("/commands", 1000, chatterCallback);
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
// %EndTag(SUBSCRIBER)%
// %Tag(SPIN)%
ros::spin(); ros::spin();
// %EndTag(SPIN)%
return 0; return 0;
} }
// %EndTag(FULLTEXT)%
// %Tag(FULLTEXT)%
// %Tag(ROS_HEADER)%
#include "ros/ros.h" #include "ros/ros.h"
// %EndTag(ROS_HEADER)% #include "std_msgs/Float64MultiArray.h"
// %Tag(MSG_HEADER)%
#include "std_msgs/String.h"
// %EndTag(MSG_HEADER)%
#include <sstream> #include <sstream>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// %Tag(INIT)%
ros::init(argc, argv, "publisher"); ros::init(argc, argv, "publisher");
// %EndTag(INIT)%
// %Tag(NODEHANDLE)%
ros::NodeHandle n; ros::NodeHandle n;
// %EndTag(NODEHANDLE)% ros::Publisher chatter_pub = n.advertise<std_msgs::Float64MultiArray>("/camera", 1000);
// %Tag(PUBLISHER)%
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
// %EndTag(PUBLISHER)%
// %Tag(LOOP_RATE)%
ros::Rate loop_rate(10); ros::Rate loop_rate(10);
// %EndTag(LOOP_RATE)%
// %Tag(ROS_OK)%
int count = 0; int count = 0;
while (ros::ok()) while (ros::ok())
{ {
// %EndTag(ROS_OK)% std_msgs::Float64MultiArray msg;
msg.data.resize(512 * 512);
// %Tag(FILL_MESSAGE)% msg.data[0] = double(count) / 1000.; // Set first bit to "iteration/1000" for debugging
std_msgs::String msg;
ROS_INFO("%f", msg.data[0]);
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
// %EndTag(FILL_MESSAGE)%
// %Tag(ROSCONSOLE)%
ROS_INFO("%s", msg.data.c_str());
// %EndTag(ROSCONSOLE)%
// %Tag(PUBLISH)%
chatter_pub.publish(msg); chatter_pub.publish(msg);
// %EndTag(PUBLISH)%
// %Tag(SPINONCE)%
ros::spinOnce(); ros::spinOnce();
// %EndTag(SPINONCE)%
// %Tag(RATE_SLEEP)%
loop_rate.sleep(); loop_rate.sleep();
// %EndTag(RATE_SLEEP)%
++count; ++count;
} }
return 0; return 0;
} }
// %EndTag(FULLTEXT)%
%!/bin/bash
echo "Building DriverController"
cd Drivercontroller
mkdir -p build
cd build
cmake ..
make -j
cd ../../
echo "Building SafetyController"
cd Safetycontroller
mkdir -p build
cd build
cmake ..
make -j
cd ../../
echo "Building FeatureExtraction"
cd Featureextraction
mkdir -p build
cd build
cmake ..
make -j
cd ../../
echo "Building ImagePreprocessing"
cd Imagepreprocessing
mkdir -p build
cd build
cmake ..
make -j
cd ../../
echo
echo "Well done!"
echo "Run ./run_all.sh to run all."
%!/bin/bash
xterm -T DriverController -e Drivercontroller/build/coordinator/Coordinator_dp_drivercontroller &
xterm -T SafetyController -e Safetycontroller/build/coordinator/Coordinator_dp_safetycontroller &
xterm -T FeatureExtraction -e Featureextraction/build/coordinator/Coordinator_dp_featureextraction &
xterm -T ImagePreprocessing -e Imagepreprocessing/build/coordinator/Coordinator_dp_imagepreprocessing &
- !de.monticar.lang.monticar.generator.python.RosTag
component: dp.drivercontroller
subscriber:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
affordanceIn: clock.toSec()
topic: /indocators
type: std_msgs/Int32
publisher:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
commandsOut: data
topic: /commands
type: std_msgs/Float64
- !de.monticar.lang.monticar.generator.python.RosTag
component: dp.featureextraction
subscriber:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
imageIn: clock.toSec()
topic: /images
type: std_msgs/Int32
publisher:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
affordanceOut: data
topic: /indicators
type: std_msgs/Float64
- !de.monticar.lang.monticar.generator.python.RosTag
component: dp.imagepreprocessing
subscriber:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
imageIn: data
topic: /camera
type: std_msgs/Int32
publisher:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
imageOut: data
topic: /images
type: std_msgs/Float64MultiArray
- !de.monticar.lang.monticar.generator.python.RosTag
component: dp.safetycontroller
subscriber:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
imageIn: clock.toSec()
affordanceIn: clock.toSec()
topic: /indicators
type: std_msgs/Int32
publisher:
- !de.monticar.lang.monticar.generator.python.RosInterface
ports:
safetyLevelOut: data
topic: /safety
type: std_msgs/Float64
...@@ -2,7 +2,7 @@ package dp; ...@@ -2,7 +2,7 @@ package dp;
component Drivercontroller { component Drivercontroller {
ports ports
in Q(0:1)^{13,1,1} affordanceIn, in Q(0:1)^{13,1} affordanceIn,
out Q(0:1)^{3,1,1} commandsOut; out Q(0:1)^{3,1} commandsOut;
} }
package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Drivercontroller {
tag drivercontroller.affordanceIn with RosConnection = {topic=(/affordance,std_msgs/Float64MultiArray)};
tag drivercontroller.commandsOut with RosConnection = {topic=(/commands,std_msgs/Float64MultiArray)};
}
...@@ -2,7 +2,7 @@ package dp; ...@@ -2,7 +2,7 @@ package dp;
component Featureextraction { component Featureextraction {
ports ports
in Z(0:255)^{3, 224, 224} imageIn, in Z(0:255)^{512,1} imageIn,
out Q(0:1)^{13,1,1} affordanceOut; out Q(0:1)^{13,1} affordanceOut;
} }
package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Featureextraction {
tag featureextraction.imageIn with RosConnection = {topic=(/images,std_msgs/Float64MultiArray)};
tag featureextraction.affordanceOut with RosConnection = {topic=(/affordance,std_msgs/Float64MultiArray)};
}
package dp; package dp;
component Imagepreprocessing { component Imagepreprocessing {
ports in Q^{3,224} in1, ports in Z(0:255)^{512,1} imageIn,
in Z^{3,224} in2, out Z(0:255)^{512,1} imageOut;
//in B^{3,224} in3,
out Q^{3,224} out1,
out Z^{3,224} out2;
//out B^{3,224} out3;
} }
...@@ -2,10 +2,6 @@ package dp; ...@@ -2,10 +2,6 @@ package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema; conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Imagepreprocessing { tags Imagepreprocessing {
tag imagepreprocessing.in1 with RosConnection = {topic=(/topicName1,std_msgs/Float64MultiArray)}; tag imagepreprocessing.imageIn with RosConnection = {topic=(/camera,std_msgs/Float64MultiArray)};
tag imagepreprocessing.in2 with RosConnection = {topic=(/topicName2,std_msgs/Int32MultiArray)}; tag imagepreprocessing.imageOut with RosConnection = {topic=(/images,std_msgs/Float64MultiArray)};
//tag imagepreprocessing.in3 with RosConnection = {topic=(/topicName3,std_msgs/ByteMultiArray)};
tag imagepreprocessing.out1 with RosConnection = {topic=(/topicName4,std_msgs/Float64MultiArray)};
tag imagepreprocessing.out2 with RosConnection = {topic=(/topicName5,std_msgs/Int32MultiArray)};
//tag imagepreprocessing.out3 with RosConnection = {topic=(/topicName6,std_msgs/ByteMultiArray)};
} }
...@@ -2,8 +2,7 @@ package dp; ...@@ -2,8 +2,7 @@ package dp;
component Safetycontroller { component Safetycontroller {
ports ports
in Z(0:255)^{3, 224, 224} imageIn, in Z(0:255)^{512,1} imageIn,
in Q(0:1)^{13,1,1} affordanceIn, in Q(0:1)^{13,1} affordanceIn,
out Q(0:1)^{1,1,1} safetyLevelOut; out Q(0:1)^{1,1} safetyLevelOut;
} }
package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Safetycontroller {
tag safetycontroller.imageIn with RosConnection = {topic=(/images,std_msgs/Float64MultiArray)};
tag safetycontroller.affordanceIn with RosConnection = {topic=(/affordance,std_msgs/Float64MultiArray)};
tag safetycontroller.safetyLevelOut with RosConnection = {topic=(/safety,std_msgs/Float64MultiArray)};
}
...@@ -26,8 +26,6 @@ public class Experiments { ...@@ -26,8 +26,6 @@ public class Experiments {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Experiments!"); System.out.println("Experiments!");
//---
Scope scope = createSymTab("resources"); Scope scope = createSymTab("resources");
TaggingResolver taggingResolver = new TaggingResolver(scope, Arrays.asList("resources")); TaggingResolver taggingResolver = new TaggingResolver(scope, Arrays.asList("resources"));
TagMinMaxTagSchema.registerTagTypes(taggingResolver); TagMinMaxTagSchema.registerTagTypes(taggingResolver);
...@@ -45,16 +43,6 @@ public class Experiments { ...@@ -45,16 +43,6 @@ public class Experiments {
middlewareGenerator.add(new CPPGenImpl(), "cpp"); middlewareGenerator.add(new CPPGenImpl(), "cpp");
middlewareGenerator.add(new RosCppGenImpl(), "roscpp"); middlewareGenerator.add(new RosCppGenImpl(), "roscpp");
// DistributedTargetGenerator distributedTargetGenerator = new DistributedTargetGenerator();
//
// distributedTargetGenerator.add(new CPPGenImpl(), "cpp");
// distributedTargetGenerator.add(new RosCppGenImpl(), "roscpp");
// GeneratorRosCpp generatorRosCpp = new GeneratorRosCpp();
// GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
LinkedList<String> inputs = new LinkedList<String>(); LinkedList<String> inputs = new LinkedList<String>();
inputs.add("Imagepreprocessing"); inputs.add("Imagepreprocessing");
inputs.add("Featureextraction"); inputs.add("Featureextraction");
...@@ -72,23 +60,6 @@ public class Experiments { ...@@ -72,23 +60,6 @@ public class Experiments {
middlewareGenerator.setGenerationTargetPath("generated/"+inpu); middlewareGenerator.setGenerationTargetPath("generated/"+inpu);
middlewareGenerator.generate(componentInstanceSymbol, taggingResolver); middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
// distributedTargetGenerator.setGenerationTargetPath("generated/"+inpu);
// distributedTargetGenerator.generate(componentInstanceSymbol, symtab);
// ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("dp."+inpu.toLowerCase(), ExpandedComponentInstanceSymbol.KIND).orElse(null);
// generatorRosMsg.setTarget("generated/", inpu);
//
// for(PortSymbol port : component.getPorts()) {
// List<File> msgFiles = generatorRosMsg.generate(port.getTypeReference());
// System.out.println(" Msg files: " + msgFiles.toString());
// }
//
// generatorRosCpp.setGenerationTargetPath("generated/"+inpu);
// List<File> files = YamlHelper.generateFromFile("resources/config/"+inpu+".yaml", symtab, generatorRosCpp);
// for (File f : files) {
// System.out.println(" " + f.toString());
// }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment