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 "std_msgs/String.h"
#include "std_msgs/Float64MultiArray.h"
// %Tag(CALLBACK)%
void chatterCallback(const std_msgs::String::ConstPtr& msg)
void chatterCallback(const std_msgs::Float64MultiArray::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)
{
......@@ -15,14 +12,8 @@ int main(int argc, char **argv)
ros::NodeHandle n;
// %Tag(SUBSCRIBER)%
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
// %EndTag(SUBSCRIBER)%
// %Tag(SPIN)%
ros::Subscriber sub = n.subscribe("/commands", 1000, chatterCallback);
ros::spin();
// %EndTag(SPIN)%
return 0;
}
// %EndTag(FULLTEXT)%
// %Tag(FULLTEXT)%
// %Tag(ROS_HEADER)%
#include "ros/ros.h"
// %EndTag(ROS_HEADER)%
// %Tag(MSG_HEADER)%
#include "std_msgs/String.h"
// %EndTag(MSG_HEADER)%
#include "std_msgs/Float64MultiArray.h"
#include <sstream>
int main(int argc, char **argv)
{
// %Tag(INIT)%
ros::init(argc, argv, "publisher");
// %EndTag(INIT)%
// %Tag(NODEHANDLE)%
ros::NodeHandle n;
// %EndTag(NODEHANDLE)%
// %Tag(PUBLISHER)%
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
// %EndTag(PUBLISHER)%
// %Tag(LOOP_RATE)%
ros::Publisher chatter_pub = n.advertise<std_msgs::Float64MultiArray>("/camera", 1000);
ros::Rate loop_rate(10);
// %EndTag(LOOP_RATE)%
// %Tag(ROS_OK)%
int count = 0;
while (ros::ok())
{
// %EndTag(ROS_OK)%
// %Tag(FILL_MESSAGE)%
std_msgs::String msg;
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)%
std_msgs::Float64MultiArray msg;
msg.data.resize(512 * 512);
msg.data[0] = double(count) / 1000.; // Set first bit to "iteration/1000" for debugging
ROS_INFO("%f", msg.data[0]);
chatter_pub.publish(msg);
// %EndTag(PUBLISH)%
// %Tag(SPINONCE)%
ros::spinOnce();
// %EndTag(SPINONCE)%
// %Tag(RATE_SLEEP)%
loop_rate.sleep();
// %EndTag(RATE_SLEEP)%
++count;
}
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;
component Drivercontroller {
ports
in Q(0:1)^{13,1,1} affordanceIn,
out Q(0:1)^{3,1,1} commandsOut;
in Q(0:1)^{13,1} affordanceIn,
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;
component Featureextraction {
ports
in Z(0:255)^{3, 224, 224} imageIn,
out Q(0:1)^{13,1,1} affordanceOut;
in Z(0:255)^{512,1} imageIn,
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;
component Imagepreprocessing {
ports in Q^{3,224} in1,
in Z^{3,224} in2,
//in B^{3,224} in3,
out Q^{3,224} out1,
out Z^{3,224} out2;
//out B^{3,224} out3;
ports in Z(0:255)^{512,1} imageIn,
out Z(0:255)^{512,1} imageOut;
}
......@@ -2,10 +2,6 @@ package dp;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Imagepreprocessing {
tag imagepreprocessing.in1 with RosConnection = {topic=(/topicName1,std_msgs/Float64MultiArray)};
tag imagepreprocessing.in2 with RosConnection = {topic=(/topicName2,std_msgs/Int32MultiArray)};
//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)};
tag imagepreprocessing.imageIn with RosConnection = {topic=(/camera,std_msgs/Float64MultiArray)};
tag imagepreprocessing.imageOut with RosConnection = {topic=(/images,std_msgs/Float64MultiArray)};
}
......@@ -2,8 +2,7 @@ package dp;
component Safetycontroller {
ports
in Z(0:255)^{3, 224, 224} imageIn,
in Q(0:1)^{13,1,1} affordanceIn,
out Q(0:1)^{1,1,1} safetyLevelOut;
in Z(0:255)^{512,1} imageIn,
in Q(0:1)^{13,1} affordanceIn,
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 {
public static void main(String[] args) {
System.out.println("Experiments!");
//---
Scope scope = createSymTab("resources");
TaggingResolver taggingResolver = new TaggingResolver(scope, Arrays.asList("resources"));
TagMinMaxTagSchema.registerTagTypes(taggingResolver);
......@@ -45,16 +43,6 @@ public class Experiments {
middlewareGenerator.add(new CPPGenImpl(), "cpp");
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>();
inputs.add("Imagepreprocessing");
inputs.add("Featureextraction");
......@@ -72,23 +60,6 @@ public class Experiments {
middlewareGenerator.setGenerationTargetPath("generated/"+inpu);
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) {
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