Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added array parameters #37

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cmake-build*
cmake-build*
build/*
25 changes: 25 additions & 0 deletions .vscode/c_cpp_properties.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the vscode config files, maybe add .vscode to the gitignore, since it contains user-specific file paths and settings.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/home/leolander/ros2_ws/install/image_geometry/include/**",
"/home/leolander/ros2_ws/install/example_interfaces/include/**",
"/home/leolander/ros2_ws/install/cv_bridge/include/**",
"/opt/ros/humble/include/**",
"/usr/include/**",
"${workspaceFolder}/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14",
"configurationProvider": "go2sh.cmake-integration"
}
],
"version": 4
}
100 changes: 100 additions & 0 deletions .vscode/settings.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this as well

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"python.autoComplete.extraPaths": [
"/home/leolander/ros2_ws/install/py_pubsub/lib/python3.10/site-packages",
"/home/leolander/ros2_ws/install/image_geometry/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/example_interfaces/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/cv_bridge/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/auv_manual_control/lib/python3.10/site-packages",
"/home/leolander/ros2_ws/install/auv_coppelia/lib/python3.10/site-packages",
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"python.analysis.extraPaths": [
"/home/leolander/ros2_ws/install/py_pubsub/lib/python3.10/site-packages",
"/home/leolander/ros2_ws/install/image_geometry/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/example_interfaces/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/cv_bridge/local/lib/python3.10/dist-packages",
"/home/leolander/ros2_ws/install/auv_manual_control/lib/python3.10/site-packages",
"/home/leolander/ros2_ws/install/auv_coppelia/lib/python3.10/site-packages",
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"files.associations": {
"*.ipp": "cpp",
"iosfwd": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
},
"ros.distro": "humble"
}
15 changes: 13 additions & 2 deletions include/ros_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@

#include <string>
#include <variant>
#include <vector>

// TODO: add arrays
using ROSParameterVariant = std::variant<bool, int, double, std::string>;
template <typename T>
struct ArrayParam {
bool isChanging;
bool isChanged;
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to look into the code again to refresh my memory on how ROSParameterVariant is used, but combining the parameter value with additional state here seems unintuitive, maybe @authaldo has opinions on that

std::vector<T> arrayValue;
};
struct BoolArrayParam : ArrayParam<bool> {};
struct IntArrayParam : ArrayParam<long int> {};
struct DoubleArrayParam : ArrayParam<double> {};
struct StringArrayParam : ArrayParam<std::string> {};
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing the byte-array parameter type. i'm ok with intentionally omitting this in the assumption that it was designed for BLOBs, but we should note that here in that case


using ROSParameterVariant = std::variant<bool, int, double, std::string, BoolArrayParam, IntArrayParam, DoubleArrayParam, StringArrayParam>;

struct ROSParameter {
ROSParameter(std::string name_, ROSParameterVariant value_) :
Expand Down
150 changes: 148 additions & 2 deletions src/parameter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ std::set<ImGuiID> visualizeParameters(ServiceWrapper &serviceWrapper,

ImGui::SameLine();
ImGui::PushItemWidth(static_cast<float>(textfieldWidth));
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_NoHostExtendX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is a constant? if so, please make it constexpr and put it next to the other constants at the start of this file. if this is mutable, we should find a better place than a static variable deep inside this function


ImVec2 outer_size = ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 3 + 3.0f);

if (std::holds_alternative<double>(value)) {
ImGui::DragScalar(identifier.c_str(), ImGuiDataType_Double, &std::get<double>(value), 1.0F, nullptr,
nullptr, "%.6g");
nullptr, "%.10g");
if (ImGui::IsItemDeactivatedAfterEdit()) {
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
Expand Down Expand Up @@ -199,7 +202,150 @@ std::set<ImGuiID> visualizeParameters(ServiceWrapper &serviceWrapper,
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
}
}
} else if (std::holds_alternative<BoolArrayParam>(value)) {
if (ImGui::BeginTable(identifier.c_str(), (std::get<BoolArrayParam>(value)).arrayValue.size(), flags, outer_size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (ImGui::BeginTable(identifier.c_str(), (std::get<BoolArrayParam>(value)).arrayValue.size(), flags, outer_size))
if (ImGui::BeginTable(identifier.c_str(), std::get<BoolArrayParam>(value).arrayValue.size(), flags, outer_size))

{
for (int cell = 0; cell < (std::get<BoolArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::PushID(cell);
ImGui::SetNextItemWidth(FLT_MIN);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 0.5*(ImGui::GetColumnWidth()) - ImGui::GetStyle().ItemSpacing.x);
bool temp = (std::get<BoolArrayParam>(value).arrayValue.at(cell)); //&vector<bool> is the c++ bug
if (ImGui::Checkbox(identifier.c_str(), &temp)) {
std::get<BoolArrayParam>(value).arrayValue.at(cell) = temp;
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
}
ImGui::PopID();
}
ImGui::TableNextRow();
for (int cell = 0; cell < (std::get<BoolArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2.3f + 0.5*(ImGui::GetColumnWidth() - ImGui::CalcTextSize(std::to_string(cell + 1).c_str()).x));
ImGui::Text("%s",std::to_string(cell + 1).c_str());
};
ImGui::EndTable();
}
} else if (std::holds_alternative<IntArrayParam>(value)) {
if (ImGui::BeginTable(identifier.c_str(), (std::get<IntArrayParam>(value)).arrayValue.size(),flags | ImGuiTableFlags_NoPadInnerX, outer_size))
{
for (int cell = 0; cell < (std::get<IntArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableSetupColumn(nullptr, ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize(std::to_string((std::get<IntArrayParam>(value)).arrayValue.at(cell)).c_str()).x + ImGui::CalcTextSize("00").x);
}
for (int cell = 0; cell < (std::get<IntArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::PushID(cell);
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::DragScalar(identifier.c_str(), ImGuiDataType_S64, &((std::get<IntArrayParam>(value)).arrayValue.at(cell)), -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above we use DragInt instead of DragScalar for integers, i don't know what the difference is but we should probably keep that consistent

ImGui::PopID();
if (ImGui::IsItemDeactivatedAfterEdit()) {
(std::get<IntArrayParam>(value)).isChanged = true;
}
if (ImGui::IsItemDeactivated()) {
(std::get<IntArrayParam>(value)).isChanging = false;
}
if (ImGui::IsItemActivated()){
(std::get<IntArrayParam>(value)).isChanging = true;
}
}
if ((std::get<IntArrayParam>(value)).isChanged && !(std::get<IntArrayParam>(value)).isChanging) {
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
(std::get<IntArrayParam>(value)).isChanged = false;
}
ImGui::TableNextRow();
for (int cell = 0; cell < (std::get<IntArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2.3f + 0.5*(ImGui::GetColumnWidth() - ImGui::CalcTextSize(std::to_string(cell + 1).c_str()).x));
ImGui::Text("%s",std::to_string(cell + 1).c_str());
};
ImGui::EndTable();
}
} else if (std::holds_alternative<DoubleArrayParam>(value)) {

if (ImGui::BeginTable(identifier.c_str(), (std::get<DoubleArrayParam>(value)).arrayValue.size(),flags | ImGuiTableFlags_NoPadInnerX, outer_size))
{
for (int cell = 0; cell < (std::get<DoubleArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableSetupColumn(nullptr, ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize(std::to_string((std::get<DoubleArrayParam>(value)).arrayValue.at(cell)).c_str()).x);
}

for (int cell = 0; cell < (std::get<DoubleArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::PushID(cell);
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::DragScalar(identifier.c_str(), ImGuiDataType_Double, &((std::get<DoubleArrayParam>(value)).arrayValue.at(cell)), 1.0F, nullptr,
nullptr, "%.10g");
ImGui::PopID();
if (ImGui::IsItemDeactivatedAfterEdit()) {
(std::get<DoubleArrayParam>(value)).isChanged = true;
}
if (ImGui::IsItemDeactivated()) {
(std::get<DoubleArrayParam>(value)).isChanging = false;
}
if (ImGui::IsItemActivated()){
(std::get<DoubleArrayParam>(value)).isChanging = true;
}
}
if ((std::get<DoubleArrayParam>(value)).isChanged && !(std::get<DoubleArrayParam>(value)).isChanging) {
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
(std::get<DoubleArrayParam>(value)).isChanged = false;
}
ImGui::TableNextRow();
for (int cell = 0; cell < (std::get<DoubleArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2.3f + 0.5*(ImGui::GetColumnWidth() - ImGui::CalcTextSize(std::to_string(cell + 1).c_str()).x));
ImGui::Text("%s",std::to_string(cell + 1).c_str());
};
ImGui::EndTable();
}
} else if (std::holds_alternative<StringArrayParam>(value)) {
if (ImGui::BeginTable(identifier.c_str(), (std::get<StringArrayParam>(value)).arrayValue.size(),flags | ImGuiTableFlags_NoPadInnerX, outer_size))
{
for (int cell = 0; cell < (std::get<StringArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableSetupColumn(nullptr, ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize((std::get<StringArrayParam>(value)).arrayValue.at(cell).c_str()).x + + ImGui::CalcTextSize("AA").x);
}
for (int cell = 0; cell < (std::get<StringArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::PushID(cell);
ImGui::SetNextItemWidth(-FLT_MIN);
ImGui::InputText(identifier.c_str(), &((std::get<StringArrayParam>(value)).arrayValue.at(cell)));
ImGui::PopID();
if (ImGui::IsItemDeactivatedAfterEdit()) {
(std::get<StringArrayParam>(value)).isChanged = true;
}
if (ImGui::IsItemDeactivated()) {
(std::get<StringArrayParam>(value)).isChanging = false;
}
if (ImGui::IsItemActivated()){
(std::get<StringArrayParam>(value)).isChanging = true;
}
}
if ((std::get<StringArrayParam>(value)).isChanged && !(std::get<StringArrayParam>(value)).isChanging) {
serviceWrapper.pushRequest(
std::make_shared<ParameterModificationRequest>(ROSParameter(fullPath, value)));
(std::get<StringArrayParam>(value)).isChanged = false;
}
ImGui::TableNextRow();
for (int cell = 0; cell < (std::get<StringArrayParam>(value)).arrayValue.size(); cell++)
{
ImGui::TableNextColumn();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2.3f + 0.5*(ImGui::GetColumnWidth() - ImGui::CalcTextSize(std::to_string(cell + 1).c_str()).x));
ImGui::Text("%s",std::to_string(cell + 1).c_str());
};
ImGui::EndTable();
}
}
ImGui::PopItemWidth();
}

Expand Down
Loading