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

Add Plugin XML Attributes to Mission XML Log #568

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
58c3fed
Initial commit
Mar 31, 2023
84bd801
Working verison, adds attribute and value and then prints the doc upd…
Apr 10, 2023
68dc6c3
Working for all plugins
Apr 10, 2023
21c7b98
Created function to parse the plugin specific xml file. This is worki…
Apr 11, 2023
c95c68a
Code cleanup
Apr 11, 2023
45508c5
Removed mission file change
Apr 11, 2023
75a9aa9
minor error message changes, added extra digit to time UI
Apr 11, 2023
812b327
Merge branch 'william-qol' of https://github.com/gtri/scrimmage into …
Apr 11, 2023
cc27377
Added returns in case of error with finding params files
Apr 11, 2023
afd20a8
Working with scrimmage_plugin_path environment variable
Apr 18, 2023
ad6b58f
Mission.plugin.xml log file added
Apr 18, 2023
a9fb57d
Code cleanup
Apr 18, 2023
2d04f5a
Initial commit of mission to mission xml pull request. Currently, abl…
May 24, 2023
36187fa
Struct is working between mission parse and sim control files. Can re…
May 25, 2023
87f2ed7
Working for updating x, y, and z pos of new entities
May 26, 2023
811875e
Removes original entity blocks
May 26, 2023
2f9d201
Additional checks/removals
May 31, 2023
b2936d3
Added tag to determine if mission 2 mission output file should be cre…
Jun 1, 2023
a5d6fce
Remove block tag working for original entities being added/removed fr…
Jun 5, 2023
4fce2a7
New final entity state file is created to view the final states of ea…
Jun 5, 2023
b8eaacb
Code cleanup
Jun 5, 2023
1e0fa94
Code cleanup
Jun 7, 2023
794e018
Working before trying to put struct with fwd decl file
Jun 7, 2023
7902c32
Struct in header is now working... do not need fwd decl or the new he…
Jun 7, 2023
b119eab
Delete EntEndStates.h
laserjetprinter Jun 7, 2023
7e6d3cb
Cleanup and support for struct in simcontrol header
Jun 7, 2023
d47c78d
Merge branch 'plugintomissionxml' of https://github.com/gtri/scrimmag…
Jun 7, 2023
1b53c6f
Updating header comments
Jun 7, 2023
683ef14
Test commit
Jun 14, 2023
d09062e
Code clean up
Jun 21, 2023
495c54a
Fixing a seg fault case based on mission xml tags
Jun 23, 2023
50e6269
Working on getting the plugin specific xml tag values. Currently am a…
Jun 26, 2023
300567f
Function working to get the xml tag values from the autonomy plugin
Jun 26, 2023
5115e3b
Rapid xml is working, writing plugin specific tags to the motion mode…
Jun 28, 2023
44a8fd7
Fully working for plugin specific xml tags populating the mission to …
Jun 30, 2023
5ae9f77
Fixed so that the plugin xml tags that are from the function overwrit…
Jun 30, 2023
35035ae
Fixed remove block tag logic
Jul 5, 2023
d54a383
Code cleanup and adding briefs
Jul 6, 2023
f5dfa48
Changing var names of miss2miss
Jul 6, 2023
09bde10
Added brief to Mission Parse header
Jul 6, 2023
4271d6a
RST file
Jul 10, 2023
318b405
Forgot to add the mission-to-mission-xml rst file
Jul 10, 2023
050e2d5
Minor updates
Jul 13, 2023
bd6a242
Merge branch 'master' of https://github.com/gtri/scrimmage into plugi…
Jul 25, 2023
ebf9605
Removing files that were used only for demoing
Aug 2, 2023
2ddb14b
Reverting William's changes to see if Docker builds
Aug 2, 2023
c025b7c
Fixed issue where docker was seg faulting for the test_openai.py file
Aug 2, 2023
c0267fa
Adding williams changes back
Aug 9, 2023
064bcd5
Merge branch 'master' of https://github.com/gtri/scrimmage into plugi…
Aug 21, 2023
fd5c886
Fixed the team id check and wording in the tutorial file
Aug 26, 2023
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
6 changes: 5 additions & 1 deletion include/scrimmage/parse/MissionParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <string>
#include <set>

#include <rapidxml/rapidxml.hpp>

namespace sp = scrimmage_proto;

namespace scrimmage {
Expand Down Expand Up @@ -161,7 +163,9 @@ class MissionParse {
protected:
std::string mission_filename_ = "";
std::string mission_file_content_ = "";

std::string plugin_file_content_ = "";
rapidxml::xml_document<> doc;

double t0_ = 0;
double tend_ = 50;
double dt_ = 0.00833333;
Expand Down
2 changes: 1 addition & 1 deletion missions/straight.xml
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this commit later - accidentally added. Used only for testing.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<run start="0.0" end="100" dt="0.1"
time_warp="10"
enable_gui="true"
enable_gui="false"
network_gui="false"
start_paused="true"
full_screen="true"
Expand Down
130 changes: 128 additions & 2 deletions src/parse/MissionParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#undef BOOST_NO_CXX11_SCOPED_ENUMS

#include <rapidxml/rapidxml.hpp>
#include <rapidxml/rapidxml_print.hpp>

using std::cout;
using std::endl;
Expand Down Expand Up @@ -83,6 +84,8 @@ void MissionParse::set_overrides(const std::string &overrides) {
bool MissionParse::parse(const std::string &filename) {
mission_filename_ = expand_user(filename);

//cout << "Natalie, filename: " << filename << " and the mission file name: " << mission_filename_ << endl;

// First, explicitly search for the mission file.
if (!fs::exists(mission_filename_)) {
// If the file doesn't exist, search for the mission file under the
Expand Down Expand Up @@ -127,7 +130,7 @@ bool MissionParse::parse(const std::string &filename) {
mission_file_content_ = std::regex_replace(mission_file_content_, reg, fmt);

// Parse the xml tree.
rapidxml::xml_document<> doc;
//rapidxml::xml_document<> doc;
// doc.parse requires a null terminated string that it can modify.
std::vector<char> mission_file_content_vec(mission_file_content_.size() + 1); // allocation done here
mission_file_content_vec.assign(mission_file_content_.begin(), mission_file_content_.end()); // copy
Expand All @@ -141,6 +144,11 @@ bool MissionParse::parse(const std::string &filename) {
return false;
}

// Natalie - this works for printing the document
std::string s;
rapidxml::print(std::back_inserter(s), doc, 0);
cout << s << endl;

rapidxml::xml_node<> *runscript_node = doc.first_node("runscript");
if (runscript_node == 0) {
cout << "Missing runscript tag." << endl;
Expand Down Expand Up @@ -518,6 +526,105 @@ bool MissionParse::parse(const std::string &filename) {
node = node->next_sibling()) {

std::string nm = node->name();

std::map<std::string, std::string> plugin_spec_attrs;
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// Plugin type: nm
// Plugin name: node->value()
// Plugin attribute name: attr->name()
// Plugin attribute value: attr->value()
//
// Need to open the plugin specific xml file if it is one of the following
// plugins:
// - Autonomy
// - Controller
// - Motion model
// - ?
//
// Starting with just the autonomy plugin, let's open that file...
if (nm == "autonomy"){
cout << "Natalie - in the autonomy file opener" << endl;
std::string plugin_file = node->value() + std::string(".xml");
std::string plugin_filename_ = expand_user(plugin_file);

// First, explicitly search for the mission file.
if (!fs::exists(plugin_filename_)) {
// If the file doesn't exist, search for the mission file under the
// SCRIMMAGE_MISSION_PATH.
FileSearch file_search;
std::string result = "";

std::string pluginxml_path = "/home/ndavis64/scrimmage/scrimmage/include/scrimmage/plugins/" + nm + "/" + node->value();

bool status = file_search.find_file(plugin_filename_, "xml",
pluginxml_path,
result, false);
if (!status) {
// The mission file wasn't found. Exit.
cout << "SCRIMMAGE mission file not found: " << plugin_filename_ << endl;
return false;
}
// The mission file was found, save its path.
plugin_filename_ = result;
}

std::ifstream file(plugin_filename_.c_str());
if (!file.is_open()) {
std::cout << "Failed to open mission file: " << plugin_filename_ << endl;
return false;
}

std::stringstream buffer;
buffer << file.rdbuf();
file.close();
plugin_file_content_ = buffer.str();

// Search and replace any overrides of the form ${key=value} in the mission
// file
for (auto &kv : overrides_map_) {
std::regex reg("\\$\\{" + kv.first + "=(.+?)\\}");
plugin_file_content_ = std::regex_replace(plugin_file_content_, reg,
kv.second);
}

// Replace our xml variables of the form ${var=default} with the default
// value
std::string fmt{"$1"};
std::regex reg("\\$\\{.+?=(.+?)\\}");
plugin_file_content_ = std::regex_replace(plugin_file_content_, reg, fmt);

// Parse the xml tree.
rapidxml::xml_document<> plugin_doc;
// doc.parse requires a null terminated string that it can modify.
std::vector<char> plugin_file_content_vec(plugin_file_content_.size() + 1); // allocation done here
plugin_file_content_vec.assign(plugin_file_content_.begin(), plugin_file_content_.end()); // copy
plugin_file_content_vec.push_back('\0'); // shouldn't reallocate
try {
// Note: This parse function can hard fail (seg fault, no exception) on
// badly formatted xml data. Sometimes it'll except, sometimes not.
plugin_doc.parse<0>(plugin_file_content_vec.data());
} catch (...) {
cout << "scrimmage::MissionParse::parse: Exception during rapidxml::xml_document<>.parse<>()." << endl;
return false;
}

rapidxml::xml_node<> *params_node = plugin_doc.first_node("params");
if (params_node == 0) {
cout << "Missing params tag." << endl;
return false;
}

for (rapidxml::xml_node<> *node = params_node->first_node(); node != 0;
node = node->next_sibling()){
plugin_spec_attrs.insert({node->name(), node->value()});
cout << "Natalie node name: " << typeid(node->name()).name() << " and the value: " << node->value() << endl;
}

}
/////////////////////////////////////////////////
/////////////////////////////////////////////////

if (nm == "autonomy") {
nm += std::to_string(autonomy_order++);
} else if (nm == "controller") {
Expand All @@ -536,16 +643,35 @@ bool MissionParse::parse(const std::string &filename) {
attr; attr = attr->next_attribute()) {

const std::string attr_name = attr->name();

if (attr_name == "param_common") {
for (auto &kv : param_common[attr->value()]) {
entity_attributes_[ent_desc_id][nm][kv.first] = kv.second;
}
} else {
if (plugin_spec_attrs[attr->name()]!=""){
cout << "The key is specified in the mission xml file, so delete it from the map." << endl;
plugin_spec_attrs.erase(attr->name());
}
entity_attributes_[ent_desc_id][nm][attr_name] = attr->value();
}
}
}

for(std::map<std::string,std::string>::iterator mapitr=plugin_spec_attrs.begin(); mapitr!=plugin_spec_attrs.end(); ++mapitr){
cout << "Natalie adding new lines to plugin: 1. " << mapitr->first << " 2. " << mapitr->second << endl;
//rapidxml::xml_attribute <> *tempattr = doc.allocate_attribute((mapitr->first).c_str(), (mapitr->second).c_str());
char *attribute_name = doc.allocate_string(mapitr->first.c_str());
char *attribute_value = doc.allocate_string(mapitr->second.c_str());
rapidxml::xml_attribute <> *tempattr = doc.allocate_attribute(attribute_name, attribute_value);
node->append_attribute(tempattr);
}

// Natalie - this works for printing the document
std::string s;
rapidxml::print(std::back_inserter(s), doc, 0);
cout << s << endl;
}

// For each entity, if the lat/lon are defined, use these values to
// overwrite the "x" and "y" values
// Search for lon lat alt.
Expand Down