Skip to content

Commit

Permalink
Added rexos-launch-ros script, HAL tester for detection EQ, and vario…
Browse files Browse the repository at this point in the history
…us bugfixes
  • Loading branch information
tommasbakker committed Apr 21, 2015
1 parent f4f5f25 commit 389efa1
Show file tree
Hide file tree
Showing 36 changed files with 843 additions and 179 deletions.
196 changes: 196 additions & 0 deletions rexos-launch-ros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#!/usr/bin/env sh
###################### VARS ######################
launchedPrimaryInfrastructureWithSimulation=false
keepWindowOpenAfterCommandEnds=true

###################### END OF VARS ######################
###################### FUNCTIONS ######################
function getEquipletName() {
echo -n "Choose equipletName: "
read equipletName
}
function getPosition() {
echo -n "Choose positionX: "
read positionX
echo -n "Choose positionY: "
read positionY
}

function launchPrimaryInfrastructureWithSimulation() {
echo "Launching primary infrastructure with simulation"
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="Primary infrastructure" \
--tab -t "roscore" -e "bash -c \"roscore\";bash" \
--tab -t "gzclient" -e "bash -c \"rosrun gazebo_ros gzserver --verbose\";bash" \
--tab -t "roscore" -e "bash -c \"rosrun gazebo_ros gzclient --verbose\";bash"
else
gnome-terminal --title="Primary infrastructure" \
--tab -t "roscore" -e "bash -c \"roscore\"" \
--tab -t "gzserver" -e "bash -c \"rosrun gazebo_ros gzserver --verbose\"" \
--tab -t "gzclient" -e "bash -c \"rosrun gazebo_ros gzclient --verbose\""
fi
launchedPrimaryInfrastructureWithSimulation=true
}

function launchPrimaryInfrastructureWithoutSimulation() {
echo "Launching primary infrastructure without simulation"
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="Primary infrastructure" \
--tab -t "roscore" -e "bash -c \"roscore\";bash"
else
gnome-terminal --title="Primary infrastructure" \
--tab -t "roscore" -e "bash -c \"roscore\""
fi
}

function launchEquipletWithPrimaryNodes() {
echo "Launching equiplet with primary nodes"
getEquipletName
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node $equipletName\";bash" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node $equipletName\"" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node $equipletName\""
fi
}

function launchEquipletWithoutPrimaryNodes() {
echo "Launching equiplet without primary nodes"
getEquipletName
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -e "bash -c \"rosrun equiplet_node equiplet_node $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -e "bash -c \"rosrun equiplet_node equiplet_node $equipletName\""
fi
}

function launchSimulatedEquipletWithoutPrimaryNodes() {
echo "Launching simulated equiplet with primary nodes"
getEquipletName
getPosition
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isSimulated $equipletName\";bash" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node --isSimulated $equipletName\";bash" \
--tab -t "model_spawner_node" -e "bash -c \"rosrun model_spawner_node model_spawner_node --spawnEquipletModel -x $positionX -y $positionY $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isSimulated $equipletName\"" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node --isSimulated $equipletName\"" \
--tab -t "model_spawner_node" -e "bash -c \"rosrun model_spawner_node model_spawner_node --spawnEquipletModel -x $positionX -y $positionY $equipletName\""
fi
}

function launchSimulatedEquipletWithPrimaryNodes() {
echo "Launching simulated equiplet without primary nodes"
getEquipletName
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isSimulated $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isSimulated $equipletName\""
fi
}

function launchShadowEquipletWithPrimaryNodes() {
echo "Launching shadow equiplet with primary nodes"
getEquipletName
getPosition
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isShadow $equipletName\";bash" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node --isShadow $equipletName\";bash" \
--tab -t "model_spawner_node" -e "bash -c \"rosrun model_spawner_node model_spawner_node --spawnEquipletModel -x $positionX -y $positionY $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isShadow $equipletName\"" \
--tab -t "node_spawner_node" -e "bash -c \"rosrun node_spawner_node node_spawner_node --isShadow $equipletName\"" \
--tab -t "model_spawner_node" -e "bash -c \"rosrun model_spawner_node model_spawner_node --spawnEquipletModel -x $positionX -y $positionY $equipletName\""
fi
}

function launchShadowEquipletWithoutPrimaryNodes() {
echo "Launching shadow equiplet without primary nodes"
getEquipletName
if [ "$keepWindowOpenAfterCommandEnds" == true ]; then
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isShadow $equipletName\";bash"
else
gnome-terminal --title="$equipletName" \
--tab -t "equiplet_node" -e "bash -c \"rosrun equiplet_node equiplet_node --isShadow $equipletName\""
fi
}
###################### END OF FUNCTIONS ######################


###################### USER INTERFACE ######################
echo "This script allows you to dynamically launch ROS components of REXOS";

echo "Step 1: choose primary infrastructure:"
echo "1: Launch primary infrastructure with simulation"
echo "2: Launch primary infrastructure without simulation"
echo "Q: Exit"
echo ""
echo -n "Choose option: "
read chosenOption

if [ "$chosenOption" == 1 ]; then
launchPrimaryInfrastructureWithSimulation
elif [ "$chosenOption" == 2 ]; then
launchPrimaryInfrastructureWithoutSimulation
elif [ "$chosenOption" == "Q" ] || [ "$chosenOption" == "q" ];
then
echo "Exiting"
exit
else
echo "Invalid option"
exit
fi

exitRequested=false

while [ "$exitRequested" == false ];
do
echo ""
echo ""
echo "Step 2: choose action:"
echo "1: Launch equiplet with primary nodes"
echo "2: Launch equiplet without primary nodes"
if [ "$launchedPrimaryInfrastructureWithSimulation" == true ]; then
echo "3: Launch simulated equiplet with primary nodes"
echo "4: Launch simulated equiplet without primary nodes"
echo "5: Launch shadow equiplet with primary nodes"
echo "6: Launch shadow equiplet without primary nodes"
echo "7: Launch equiplet model and module models only"
echo "8: Launch part model"
fi
echo "Q: Exit"
echo ""
echo -n "Choose option: "
read chosenOption

if [ "$chosenOption" == 1 ]; then
launchEquipletWithPrimaryNodes
elif [ "$chosenOption" == 2 ]; then
launchEquipletWithoutPrimaryNodes
elif [ "$chosenOption" == 3 ] && [ "$launchedPrimaryInfrastructureWithSimulation" == true ]; then
launchSimulatedEquipletWithoutPrimaryNodes
elif [ "$chosenOption" == 4 ] && [ "$launchedPrimaryInfrastructureWithSimulation" == true ]; then
launchSimulatedEquipletWithPrimaryNodes
elif [ "$chosenOption" == 5 ] && [ "$launchedPrimaryInfrastructureWithSimulation" == true ]; then
launchShadowEquipletWithPrimaryNodes
elif [ "$chosenOption" == 6 ] && [ "$launchedPrimaryInfrastructureWithSimulation" == true ]; then
launchShadowEquipletWithoutPrimaryNodes
elif [ "$chosenOption" == "Q" ] || [ "$chosenOption" == "q" ]; then
echo "Exiting"
exitRequested=true
else echo "Invalid option"
fi
done
###################### END OF USER INTERFACE ######################
4 changes: 4 additions & 0 deletions src/REXOS/HAL/dataTypes/GazeboModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public GazeboModel(int id, int buildNumber, byte[] zipFile, String sdfFilename,
public static GazeboModel getGazeboModelForModuleIdentifier(ModuleTypeIdentifier moduleIdentifier, KnowledgeDBClient knowledgeDBClient) {
Row[] rows = knowledgeDBClient.executeSelectQuery(getGazeboModelForModuleType, moduleIdentifier.manufacturer, moduleIdentifier.typeNumber);

if(rows.length != 1) {
return null;
}

int id = (Integer) rows[0].get("id");
int buildNumber = (Integer) rows[0].get("buildNumber");
String sdfFilename = (String) rows[0].get("sdfFilename");
Expand Down
4 changes: 4 additions & 0 deletions src/REXOS/HAL/dataTypes/JavaSoftware.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public static JavaSoftware getJavaSoftwareForId(int id, KnowledgeDBClient knowle
public static JavaSoftware getJavaSoftwareForModuleIdentifier(ModuleTypeIdentifier moduleIdentifier, KnowledgeDBClient knowledgeDBClient) {
Row[] rows = knowledgeDBClient.executeSelectQuery(getJavaSoftwareForModuleType, moduleIdentifier.manufacturer, moduleIdentifier.typeNumber);

if(rows.length != 1) {
return null;
}

int id = (Integer) rows[0].get("id");
int buildNumber = (Integer) rows[0].get("buildNumber");
String className = (String) rows[0].get("className");
Expand Down
60 changes: 38 additions & 22 deletions src/REXOS/HAL/dataTypes/ModuleType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.omg.PortableInterceptor.INACTIVE;

import util.log.LogLevel;
import util.log.LogSection;
Expand Down Expand Up @@ -196,31 +197,46 @@ public void insertIntoDatabase(KnowledgeDBClient knowledgeDBClient) throws JSONE
* @throws JSONException
*/
private void updateModuleType(KnowledgeDBClient knowledgeDBClient) {
JavaSoftware currentJavaSoftware = JavaSoftware.getJavaSoftwareForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int newJavaBuildNumber = halSoftware.buildNumber;
int currentJavaBuildNumber = currentJavaSoftware.buildNumber;
if (newJavaBuildNumber > currentJavaBuildNumber) {
// update the halSoftware
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating HAL software for module " + moduleTypeIdentifier);
halSoftware.updateDatabase(currentJavaSoftware, knowledgeDBClient);
if(halSoftware != null) {
JavaSoftware currentJavaSoftware = JavaSoftware.getJavaSoftwareForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int currentJavaBuildNumber;
if(currentJavaSoftware == null) currentJavaBuildNumber = Integer.MIN_VALUE;
else currentJavaBuildNumber = currentJavaSoftware.buildNumber;

int newJavaBuildNumber = halSoftware.buildNumber;
if (newJavaBuildNumber > currentJavaBuildNumber) {
// update the halSoftware
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating HAL software for module " + moduleTypeIdentifier);
halSoftware.updateDatabase(currentJavaSoftware, knowledgeDBClient);
}
}

RosSoftware currentRosSoftware = RosSoftware.getRosSoftwareForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int newRosBuildNumber = rosSoftware.buildNumber;
int currentRosBuildNumber = currentRosSoftware.buildNumber;
if (newRosBuildNumber > currentRosBuildNumber) {
// update the rosSoftware
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating ROS software for module " + moduleTypeIdentifier);
rosSoftware.updateDatabase(currentRosSoftware, knowledgeDBClient);

if(rosSoftware != null) {
RosSoftware currentRosSoftware = RosSoftware.getRosSoftwareForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int currentRosBuildNumber;
if(currentRosSoftware == null) currentRosBuildNumber = Integer.MIN_VALUE;
else currentRosBuildNumber = currentRosSoftware.buildNumber;

int newRosBuildNumber = rosSoftware.buildNumber;
if (newRosBuildNumber > currentRosBuildNumber) {
// update the rosSoftware
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating ROS software for module " + moduleTypeIdentifier);
rosSoftware.updateDatabase(currentRosSoftware, knowledgeDBClient);
}
}

GazeboModel currentGazeboModel = GazeboModel.getGazeboModelForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int newModelBuildNumber = gazeboModel.buildNumber;
int currentModelBuildNumber = currentGazeboModel.buildNumber;
if (newModelBuildNumber > currentModelBuildNumber) {
// update the gazeboModel
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating Gazebo model for module " + moduleTypeIdentifier);
gazeboModel.updateGazeboModel(currentGazeboModel, knowledgeDBClient);
if(gazeboModel != null) {
GazeboModel currentGazeboModel = GazeboModel.getGazeboModelForModuleIdentifier(moduleTypeIdentifier, knowledgeDBClient);
int currentModelBuildNumber;
if(currentGazeboModel == null) currentModelBuildNumber = Integer.MIN_VALUE;
else currentModelBuildNumber = currentGazeboModel.buildNumber;

int newModelBuildNumber = gazeboModel.buildNumber;
if (newModelBuildNumber > currentModelBuildNumber) {
// update the gazeboModel
Logger.log(LogSection.HAL_MODULE_FACTORY, LogLevel.INFORMATION, "Updating Gazebo model for module " + moduleTypeIdentifier);
gazeboModel.updateGazeboModel(currentGazeboModel, knowledgeDBClient);
}
}

for (SerializedCapability capability : capabilities) {
Expand Down
4 changes: 4 additions & 0 deletions src/REXOS/HAL/dataTypes/RosSoftware.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public static RosSoftware getRosSoftwareForId(int id, KnowledgeDBClient knowledg
public static RosSoftware getRosSoftwareForModuleIdentifier(ModuleTypeIdentifier moduleIdentifier, KnowledgeDBClient knowledgeDBClient) {
Row[] rows = knowledgeDBClient.executeSelectQuery(getRosSoftwareForModuleType, moduleIdentifier.manufacturer, moduleIdentifier.typeNumber);

if(rows.length != 1) {
return null;
}

int id = (Integer) rows[0].get("id");
int buildNumber = (Integer) rows[0].get("buildNumber");
String command = (String) rows[0].get("command");
Expand Down
7 changes: 6 additions & 1 deletion src/REXOS/HAL/testerClasses/EquipletRecordLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@

public class EquipletRecordLoader {

static String equipletName = "EQ2";
static String equipletName = "EQ3";

public static void main(String[] args) throws JSONException, IOException {
if(args.length >= 1) {
equipletName = args[0];
}
System.out.println("Inserting equiplet " + equipletName);

KnowledgeDBClient client = new KnowledgeDBClient();

JSONObject javaSoftwareJson = new JSONObject();
Expand Down
7 changes: 6 additions & 1 deletion src/REXOS/HAL/testerClasses/HALTesterClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class HALTesterClass implements HardwareAbstractionLayerListener {
HardwareAbstractionLayer hal;

static final String equipletName = "EQ3";
static String equipletName = "EQ3";
static final String baseDir = "generatedOutput/";

// dummy module A
Expand Down Expand Up @@ -120,6 +120,11 @@ public class HALTesterClass implements HardwareAbstractionLayerListener {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
if(args.length >= 1) {
equipletName = args[0];
}
System.out.println("Inserting equiplet " + equipletName);

@SuppressWarnings("unused")
HALTesterClass htc = new HALTesterClass();
htc = null;
Expand Down
Loading

0 comments on commit 389efa1

Please sign in to comment.