Skip to content

Commit

Permalink
Devcontainer isaac and analyst (#99)
Browse files Browse the repository at this point in the history
* making spawn changes and adding double handed cargo

* adding devcontainer file

* clean up analyst query demo; save and upload database scripts

* making multiple bag loading collection creation not clash

* adding multiple devcontainer profiles; load database progress

* adding main for running standalone

* small changes from database upload

* fix lint
  • Loading branch information
marinagmoreira authored Jul 12, 2023
1 parent e7ef39d commit 4c9c3ff
Show file tree
Hide file tree
Showing 17 changed files with 681 additions and 347 deletions.
2 changes: 2 additions & 0 deletions .devcontainer/analyst/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ghcr.io/nasa/isaac_analyst_notebook
ENV DEBIAN_FRONTEND=dialog
47 changes: 47 additions & 0 deletions .devcontainer/analyst/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"dockerFile": "Dockerfile",
"build": {
"args": {
"WORKSPACE": "${containerWorkspaceFolder}"
}
},
"remoteUser": "root",
"runArgs": [
"--network=host",
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp:unconfined",
"--security-opt=apparmor:unconfined",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix"
],
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl
},
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
},
"extensions": [
// "althack.ament-task-provider",
"DotJoshJohnson.xml",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"smilerobotics.urdf",
"streetsidesoftware.code-spell-checker",
"twxs.cmake",
"yzhang.markdown-all-in-one",
"zachflower.uncrustify"
],
"mounts": [
"source=${localWorkspaceFolder},target=/src/isaac/src,type=bind,consistency=cached",
"source=${localWorkspaceFolder}/../../astrobee/src,target=/src/astrobee/src,type=bind,consistency=cached"
],
"workspaceFolder": "/src/isaac/src"
}
2 changes: 2 additions & 0 deletions .devcontainer/isaac/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ghcr.io/nasa/isaac_analyst_notebook
ENV DEBIAN_FRONTEND=dialog
47 changes: 47 additions & 0 deletions .devcontainer/isaac/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"dockerFile": "Dockerfile",
"build": {
"args": {
"WORKSPACE": "${containerWorkspaceFolder}"
}
},
"remoteUser": "root",
"runArgs": [
"--network=host",
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp:unconfined",
"--security-opt=apparmor:unconfined",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix"
],
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl
},
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
},
"extensions": [
// "althack.ament-task-provider",
"DotJoshJohnson.xml",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"smilerobotics.urdf",
"streetsidesoftware.code-spell-checker",
"twxs.cmake",
"yzhang.markdown-all-in-one",
"zachflower.uncrustify"
],
"mounts": [
"source=${localWorkspaceFolder},target=/src/isaac/src,type=bind,consistency=cached",
"source=${localWorkspaceFolder}/../../astrobee/src,target=/src/astrobee/src,type=bind,consistency=cached"
],
"workspaceFolder": "/src/isaac/src"
}
2 changes: 2 additions & 0 deletions .devcontainer/remote/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ghcr.io/nasa/isaac_analyst_notebook
ENV DEBIAN_FRONTEND=dialog
47 changes: 47 additions & 0 deletions .devcontainer/remote/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"dockerFile": "Dockerfile",
"build": {
"args": {
"WORKSPACE": "${containerWorkspaceFolder}"
}
},
"remoteUser": "root",
"runArgs": [
"--network=host",
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp:unconfined",
"--security-opt=apparmor:unconfined",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix"
],
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl
},
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
},
"extensions": [
// "althack.ament-task-provider",
"DotJoshJohnson.xml",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"smilerobotics.urdf",
"streetsidesoftware.code-spell-checker",
"twxs.cmake",
"yzhang.markdown-all-in-one",
"zachflower.uncrustify"
],
"mounts": [
"source=${localWorkspaceFolder},target=/src/isaac/src,type=bind,consistency=cached",
"source=${localWorkspaceFolder}/../../astrobee/src,target=/src/astrobee/src,type=bind,consistency=cached"
],
"workspaceFolder": "/src/isaac/src"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ analyst/workspace/.ipython
analyst/workspace/.jupyter
analyst/workspace/.local
analyst/workspace/.ipynb_checkpoints
analyst/workspace/scripts/.ipynb_checkpoints
analyst/workspace/.cache
analyst/workspace/data

# vscode
isaac.code-workspace
112 changes: 74 additions & 38 deletions analyst/tools/query_view_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ DEFINE_string(camera, "sci_cam", "Camera name.");
DEFINE_double(min_distance, 0.2, "Anomaly: minimum distance to target (m)");
DEFINE_double(max_distance, 0.7, "Anomaly: maximum distance to target (m)");

Eigen::Vector3d read_vector(Json::Value element) {
Eigen::Vector3d vector_out;
vector_out[0] = element[0].asFloat();
vector_out[1] = element[1].asFloat();
vector_out[2] = element[2].asFloat();
return vector_out;
}

Eigen::Vector2d rescale_image(Eigen::Vector2d cam_size, int x, int y, int width, int height) {
Eigen::Vector2d vector_out;
vector_out[0] = x * width / cam_size[0];
vector_out[1] = y * height / cam_size[1];
return vector_out;
}
Json::Value vector_2d_to_json(Eigen::Vector2d coord) {
Json::Value coord_json;
coord_json[0] = coord[0];
coord_json[1] = coord[1];
return coord_json;
}

int main(int argc, char** argv) {
// Gather some data from the command
google::SetUsageMessage("Usage: rosrun inspection query_view_points <opts>");
Expand Down Expand Up @@ -96,9 +117,6 @@ int main(int argc, char** argv) {
inspection::CameraView camera(cam_params, 2.0, 0.19, msg_pointer);





// Extract the input list from the command-line argument
std::string input_json = argv[1];

Expand All @@ -113,54 +131,72 @@ int main(int argc, char** argv) {
std::cerr << "Input JSON does not represent an array." << std::endl;
return 1;
}
std::stringstream output_json;
Json::Value output_json;
// Process each list element
for (const auto& element : json) {
// Assuming each list element has two dictionaries
if (element.size() != 2 || !element[0].isObject() || !element[1].isArray()) {
std::cerr << "Invalid list element encountered." << std::endl;
if (element.size() != 13) {
std::cerr << "Invalid list element encountered. Haz size " << element.size() << std::endl;
continue;
}

// // Extract values from the first dictionary
// const Json::Value& dict1 = element[0];
// // Access the values using the desired keys
// int seq = dict1["seq"].asInt();
// int secs = dict1["stamp"]["secs"].asInt();
// int nsecs = dict1["stamp"]["nsecs"].asInt();
// std::string frame_id = dict1["frame_id"].asString();

// Extract values from the second dictionary (assuming it contains 7 float values)
const Json::Value& dict = element[1];
std::vector<float> floatValues;
for (const auto& value : dict) {
if (value.isConvertibleTo(Json::realValue))
floatValues.push_back(value.asFloat());
}

Eigen::Vector3d target;
target[0] = element[1][0].asFloat();
target[1] = element[1][1].asFloat();
target[2] = element[1][2].asFloat();
geometry_msgs::Pose ground_truth;
ground_truth.position.x = element[1][3].asFloat();
ground_truth.position.y = element[1][4].asFloat();
ground_truth.position.z = element[1][5].asFloat();
ground_truth.orientation.x = element[1][6].asFloat();
ground_truth.orientation.y = element[1][7].asFloat();
ground_truth.orientation.z = element[1][8].asFloat();
ground_truth.orientation.w = element[1][9].asFloat();
ground_truth.position.x = element[1].asFloat();
ground_truth.position.y = element[2].asFloat();
ground_truth.position.z = element[3].asFloat();
ground_truth.orientation.x = element[4].asFloat();
ground_truth.orientation.y = element[5].asFloat();
ground_truth.orientation.z = element[6].asFloat();
ground_truth.orientation.w = element[7].asFloat();
Eigen::Vector3d target = read_vector(element[8]);
Eigen::Vector3d c1 = read_vector(element[9]);
Eigen::Vector3d c2 = read_vector(element[10]);
Eigen::Vector3d c3 = read_vector(element[11]);
Eigen::Vector3d c4 = read_vector(element[12]);

int x, y;

if (camera.GetCamXYFromPoint((msg_conversions::ros_pose_to_eigen_transform(ground_truth) *
transform_body_to_cam).inverse(), target, x, y)) {
output_json << element;
int height = 4008;
int width = 5344;
int c1_x, c1_y, c2_x, c2_y, c3_x, c3_y, c4_x, c4_y;
if (camera.GetCamXYFromPoint(msg_conversions::ros_pose_to_eigen_transform(ground_truth), target, x, y)) {
Json::Value output_element_json;
output_element_json["img"] = element[0];

Eigen::Vector2d cam_size = (cam_params.GetDistortedSize()).cast<double>();

Eigen::Vector2d coord = rescale_image(cam_size, x, y, width, height);
output_element_json["coord"] = vector_2d_to_json(coord);

if (!camera.GetCamXYFromPoint(msg_conversions::ros_pose_to_eigen_transform(ground_truth), c1, c1_x, c1_y)) {
continue;
}
Eigen::Vector2d coord_c1 = rescale_image(cam_size, c1_x, c1_y, width, height);
output_element_json["coord_c1"] = vector_2d_to_json(coord_c1);

if (!camera.GetCamXYFromPoint(msg_conversions::ros_pose_to_eigen_transform(ground_truth), c2, c2_x, c2_y)) {
continue;
}
Eigen::Vector2d coord_c2 = rescale_image(cam_size, c2_x, c2_y, width, height);
output_element_json["coord_c2"] = vector_2d_to_json(coord_c2);

if (!camera.GetCamXYFromPoint(msg_conversions::ros_pose_to_eigen_transform(ground_truth), c3, c3_x, c3_y)) {
continue;
}
Eigen::Vector2d coord_c3 = rescale_image(cam_size, c3_x, c3_y, width, height);
output_element_json["coord_c3"] = vector_2d_to_json(coord_c3);

if (!camera.GetCamXYFromPoint(msg_conversions::ros_pose_to_eigen_transform(ground_truth), c4, c4_x, c4_y)) {
continue;
}
Eigen::Vector2d coord_c4 = rescale_image(cam_size, c4_x, c4_y, width, height);
output_element_json["coord_c4"] = vector_2d_to_json(coord_c4);

output_json.append(output_element_json);
}
}

// Print the output JSON
std::cout << output_json.str() << std::endl;
std::cout << output_json << std::endl;

// Finish commandline flags
google::ShutDownCommandLineFlags();
Expand Down
33 changes: 1 addition & 32 deletions analyst/workspace/1_import_bagfiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,7 @@
"\n",
"The database used is ArangoDB. If you followed the Analyst notebook startup procedure [here](https://nasa.github.io/isaac/html/index.html), the local database should already be hosted in http://localhost:8529.\n",
"\n",
"Go ahead open the link at take a look! The username is `root` and the password `isaac`.\n",
"\n",
"To connect to the database:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connected to database!\n"
]
}
],
"source": [
"from pyArango.connection import *\n",
"\n",
"# Connect to the database\n",
"conn = Connection(arangoURL=\"http://iui_arangodb:8529\", username=\"root\", password=\"isaac\")\n",
"\n",
"# Open the isaac database / create it if it does not exist\n",
"if not conn.hasDatabase(\"isaac\"):\n",
" conn.createDatabase(name=\"isaac\")\n",
" \n",
"db = conn[\"isaac\"] \n",
"print(\"Connected to database!\")"
"Go ahead open the link at take a look! The username is `root` and the password `isaac`."
]
},
{
Expand Down
Loading

0 comments on commit 4c9c3ff

Please sign in to comment.