Skip to content

Commit

Permalink
changing picture taking command to new name (nasa#359)
Browse files Browse the repository at this point in the history
* changing picture taking command to new name

* Changed continuous picture taking command.

* Removed old code.

Co-authored-by: Katie Browne <[email protected]>
  • Loading branch information
marinagmoreira and kbrowne15 authored Dec 13, 2021
1 parent 24d9125 commit 1866bc6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
7 changes: 7 additions & 0 deletions simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ find_package(catkin2 REQUIRED COMPONENTS
ff_util
gnc_autocode
camera
jsonloader
)

# Find packages
find_package(gazebo REQUIRED)

# Find jsoncpp
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake")
find_package(JsonCpp REQUIRED)

# Add gazebo to the link directorries
link_directories(${GAZEBO_LIBRARY_DIRS})

Expand Down Expand Up @@ -88,6 +93,7 @@ catkin_package(
ff_util
gnc_autocode
camera
jsonloader
)


Expand All @@ -100,6 +106,7 @@ include_directories(
include
${catkin_INCLUDE_DIRS}
${GAZEBO_INCLUDE_DIRS}
${JSONCPP_INCLUDE_DIRS}
)

link_directories(${GAZEBO_LIBRARY_DIRS})
Expand Down
2 changes: 2 additions & 0 deletions simulation/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<build_depend>ff_util</build_depend>
<build_depend>gnc_autocode</build_depend>
<build_depend>camera</build_depend>
<build_depend>jsonloader</build_depend>
<run_depend>visualization_msgs</run_depend>
<run_depend>tf2</run_depend>
<run_depend>tf2_ros</run_depend>
Expand All @@ -42,6 +43,7 @@
<run_depend>ff_util</run_depend>
<run_depend>gnc_autocode</run_depend>
<run_depend>camera</run_depend>
<run_depend>jsonloader</run_depend>
<export>
<gazebo_ros plugin_path="${prefix}/lib"/>
<gazebo_ros gazebo_model_path="${prefix}/../description/media"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
// FSW includes
#include <config_reader/config_reader.h>

// JSON includes
#include <json/json.h>
#include <json/value.h>
#include <jsonloader/planio.h>

// Sensor plugin interface
#include <astrobee_gazebo/astrobee_gazebo.h>

Expand Down Expand Up @@ -156,30 +161,6 @@ class GazeboSensorPluginSciCam : public FreeFlyerSensorPlugin {
}
}

// Out of string: "{"name": "turnOnContinuousPictureTaking"}"
// collect the part in the second set of quotes.
// Some honest json parsing could be used here.
std::string parseJsonStr(std::string const& json_str) {
size_t start = 0;
size_t colon_pos = json_str.find(":", start);
if (colon_pos == std::string::npos) {
return "";
}
size_t quote1_pos = json_str.find("\"", colon_pos + 1);
if (quote1_pos == std::string::npos) {
return "";
}
size_t quote2_pos = json_str.find("\"", quote1_pos + 1);

if (quote2_pos == std::string::npos) {
return "";
}

std::string parsed = json_str.substr(quote1_pos + 1, quote2_pos - quote1_pos - 1);

return parsed;
}

// Called when a dds command is received. Process only guest science
// sci cam control commands.
void CmdCallback(ff_msgs::CommandStamped const& cmd) {
Expand All @@ -199,7 +180,7 @@ class GazeboSensorPluginSciCam : public FreeFlyerSensorPlugin {
return;
}

std::string app_name = cmd.args[0].s.data();
std::string app_name = cmd.args[0].s.data();

// Process only sci cam commands
if (app_name != "gov.nasa.arc.irg.astrobee.sci_cam_image") {
Expand All @@ -209,22 +190,40 @@ class GazeboSensorPluginSciCam : public FreeFlyerSensorPlugin {
std::string json_str = cmd.args[1].s.data();
ROS_INFO_STREAM("Received command: " << json_str);

std::string action = parseJsonStr(json_str);
if (action == "")
// Convert string into a json object
Json::Value cmd_obj;
if (!jsonloader::LoadData(json_str, &cmd_obj)) {
ROS_ERROR_STREAM("Unable to convert command " << json_str << " to json.");
return;
}

// Check to make sure command name exists
if (!cmd_obj.isMember("name") || !cmd_obj["name"].isString()) {
ROS_ERROR_STREAM(json_str << " doesn't contain name for the command.");
return;
}

std::string action = cmd_obj["name"].asString();

// Record the desired intention. Use a lock.
{
const std::lock_guard<std::mutex> lock(sci_cam_image_lock);
if (action == "takeSinglePicture") {
if (action == "takePicture") {
takeSinglePicture_ = true;
continuousPictureTaking_ = false;
} else if (action == "turnOnContinuousPictureTaking") {
takeSinglePicture_ = false;
continuousPictureTaking_ = true;
} else if (action == "turnOffContinuousPictureTaking") {
takeSinglePicture_ = false;
continuousPictureTaking_ = false;
} else if (action == "setContinuousPictureTaking") {
if (cmd_obj.isMember("continuous") && cmd_obj["continuous"].isBool()) {
if (cmd_obj["continuous"].asBool()) {
takeSinglePicture_ = false;
continuousPictureTaking_ = true;
} else {
takeSinglePicture_ = false;
continuousPictureTaking_ = false;
}
} else {
ROS_ERROR_STREAM("Got set continuous picture taking command but it" <<
" didn't contain the continuous argument.");
}
} else {
ROS_FATAL_STREAM("Unknown sci_cam command: " << action);
}
Expand Down

0 comments on commit 1866bc6

Please sign in to comment.