-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Changes from all commits
5446b3e
bb938da
7704d14
a712d96
8977040
4ae17ae
cc95edf
9462577
067aa58
69d5297
8a5e5e5
badb399
bc73fd2
04dd925
8ed5706
eeb0a5a
f63b232
d82456f
3d734e8
3a8ce10
e4ee9ef
445b2e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
cmake-build* | ||
cmake-build* | ||
build/* |
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 | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_) : | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is a constant? if so, please make it |
||||||
|
||||||
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))); | ||||||
|
@@ -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)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above we use |
||||||
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(); | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
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.