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 37 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
3 changes: 3 additions & 0 deletions include/scrimmage/autonomy/Autonomy.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Autonomy : public EntityPlugin {
void close(double t) override;
bool need_reset();

// Mission to mission function
virtual std::map<std::string,std::string> mission_xml_set();

// getters/setters
StatePtr &desired_state();
void set_desired_state(StatePtr desired_state);
Expand Down
7 changes: 7 additions & 0 deletions include/scrimmage/entity/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class Entity : public std::enable_shared_from_this<Entity> {
MotionModelPtr &motion();
std::vector<ControllerPtr> &controllers();

// Mission to mission pull request
std::map<std::string,std::string> set_motion_xml_vect();
std::vector<std::map<std::string,std::string>> set_sensor_xml_vect();
std::vector<std::map<std::string,std::string>> set_autonomy_xml_vect();
std::vector<std::map<std::string,std::string>> set_controller_xml_vect();
// End of mission to mission

void set_id(ID &id);
ID &id();

Expand Down
7 changes: 7 additions & 0 deletions include/scrimmage/motion/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Controller : public EntityPlugin {
desired_state_ = nullptr;
}

// Mission to mission function
virtual std::map<std::string,std::string> mission_xml_set() {
std::map<std::string,std::string> mission_xml;
return mission_xml;
};


protected:
StatePtr state_;
StatePtr desired_state_;
Expand Down
4 changes: 4 additions & 0 deletions include/scrimmage/motion/MotionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class MotionModel : public EntityPlugin {
std::map<std::string, std::string> &params);

virtual bool step(double time, double dt);

// Mission to mission function
virtual std::map<std::string,std::string> mission_xml_set();

virtual bool posthumous(double t);
virtual StatePtr &state();
virtual void set_state(StatePtr &state);
Expand Down
20 changes: 20 additions & 0 deletions include/scrimmage/parse/MissionParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <scrimmage/proto/Visual.pb.h>

#include <scrimmage/proto/Color.pb.h>
#include <scrimmage/simcontrol/SimControl.h>
#include <rapidxml/rapidxml.hpp>

#include <list>
#include <vector>
Expand Down Expand Up @@ -84,6 +86,15 @@ class MissionParse {
bool create_log_dir();
void set_overrides(const std::string &overrides);
bool parse(const std::string &filename);
void get_plugin_params(std::string node_name, std::string node_value);

/// @brief Generate the mission to mission xml file for all final states of entities
/// @param all_end_states
void final_state_xml(std::list<SimControl::ent_end_state> & all_end_states);

/// @brief Track the number of entity blocks in the input Mission XML file
int num_ents = 0;

bool write(const std::string &filename);

double t0();
Expand Down Expand Up @@ -159,9 +170,18 @@ class MissionParse {
bool output_type_required(const std::string& output_type);

protected:
rapidxml::xml_document<> doc;

std::string mission_filename_ = "";
std::string mission_file_content_ = "";

std::string miss2miss_file_content = "";
std::stringstream ent_state_file_content;

std::string mission_plugin_file_content = "";
std::string scrimmage_plugin_path = "";
std::map<std::string, std::string> plugin_spec_attrs;

double t0_ = 0;
double tend_ = 50;
double dt_ = 0.00833333;
Expand Down
1 change: 1 addition & 0 deletions include/scrimmage/plugins/autonomy/Straight/Straight.h
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 file after writing the tutorial files

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Straight : public scrimmage::Autonomy{
public:
void init(std::map<std::string, std::string> &params) override;
bool step_autonomy(double t, double dt) override;
std::map<std::string,std::string> mission_xml_set() override;

protected:
double speed_;
Expand Down
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 file after writing the tutorial files

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class SimpleAircraftControllerPID : public Controller {
public:
virtual void init(std::map<std::string, std::string> &params);
virtual bool step(double t, double dt);
std::map<std::string,std::string> mission_xml_set() override;


protected:
scrimmage::PID heading_pid_;
Expand Down
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 file after writing the tutorial files

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class SimpleAircraft : public scrimmage::MotionModel{

void teleport(scrimmage::StatePtr &state) override;

std::map<std::string,std::string> mission_xml_set() override;

protected:
scrimmage::PID heading_pid_;
scrimmage::PID alt_pid_;
Expand Down
6 changes: 6 additions & 0 deletions include/scrimmage/sensor/Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Sensor : public EntityPlugin {

virtual bool step() {return true;}

// Mission to mission function
virtual std::map<std::string,std::string> mission_xml_set() {
std::map<std::string,std::string> mission_xml;
return mission_xml;
};

virtual scrimmage::MessageBasePtr sensor_msg(double t);

/*! \brief version when T = MessageBase (calls sensor_msg without casting) */
Expand Down
29 changes: 29 additions & 0 deletions include/scrimmage/simcontrol/SimControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,32 @@ class SimControl {

void set_running_in_thread(bool running_in_thread);

/// @brief Contains the final state values of each entity
struct ent_end_state {
int team_id;
double x_pos;
double y_pos;
double z_pos;

double yaw;
double pitch;
double roll;

int health_points;

double vel_x;
double vel_y;
double vel_z;

std::map<std::string,std::string> motion_xml_tags;
std::vector<std::map<std::string,std::string>> autonomy_xml_tags;
std::vector<std::map<std::string,std::string>> controller_xml_tags;
std::vector<std::map<std::string,std::string>> sensor_xml_tags;

} end_state;

std::list<ent_end_state> all_end_states;

protected:
// Key: Entity ID
// Value: Team ID
Expand Down Expand Up @@ -364,6 +390,9 @@ class SimControl {
bool finished_ = false;
bool exit_ = false;

/// @brief Holds the mission_to_mission tag. If true, will create an output XML file of final entity states
bool miss2miss = false;

std::mutex finished_mutex_;
std::mutex contacts_mutex_;
std::mutex exit_mutex_;
Expand Down
5 changes: 5 additions & 0 deletions src/autonomy/Autonomy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ void Autonomy::init() {}
void Autonomy::init(std::map<std::string, std::string> &/*params*/) {}
bool Autonomy::need_reset() {return need_reset_;}

std::map<std::string,std::string> Autonomy::mission_xml_set() {
std::map<std::string,std::string> mission_xml;
return mission_xml;
}

StatePtr &Autonomy::desired_state() {return desired_state_;}

void Autonomy::set_desired_state(StatePtr desired_state) {desired_state_ = desired_state;}
Expand Down
95 changes: 93 additions & 2 deletions src/entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,99 @@ void Entity::print_plugins(std::ostream &out) const {
out << c->name() << endl;
}
out << "----------- Motion -------------" << endl;
if (motion_model_->name() != "BLANK") {
if (motion_model_ && motion_model_->name() != "BLANK") {
out << motion_model_->name() << endl;
}
}
} // namespace scrimmage

// Function that creates some kind of data structure based off the sensors, autonomies,
// controllers, and motion models.
// The plugins can call the function to pass their plugin specific xml values, which will
// be added to the corresponding plugin stored in the data structure
// Might be good to have a function for each plugin type, instead of combining them like in the
// print plugins function
// In the case the xml tag is a vector of PID, could do a type check in the mission parse file and
// update accordingly

// Note: all data passed from the mission_xml_set function should be formatted as a map of strings
// to strings. This will assist with the Rapid XML formatting. Additionally, the first entry of the map
// must be the name of the given plugin - for example: "Straight" for an autonomy plugin.

std::map<std::string,std::string> Entity::set_motion_xml_vect(){
std::map<std::string,std::string> cur_motion_xml;
if (motion_model_ && motion_model_->name() != "BLANK") {
cur_motion_xml = motion_model_->mission_xml_set();

// Verifies the motion model has the expected xml specific tags. This can be uncommented for debugging.
// for (auto itr = cur_motion_xml.begin(); itr != cur_motion_xml.end(); ++itr) {
// std::cout << "Motion Model: 1. " << itr->first << " 2. " << itr->second << std::endl;
// }
}

return cur_motion_xml;
}

std::vector<std::map<std::string,std::string>> Entity::set_sensor_xml_vect(){
std::vector<std::map<std::string,std::string>> all_sensor_xml;
std::map<std::string,std::string> cur_sensor_xml;

for (auto &kv : sensors_) {
cur_sensor_xml = kv.second->mission_xml_set();
all_sensor_xml.push_back(cur_sensor_xml);
}

// Verifies each sensor has the expected xml specific tags. This can be uncommented for debugging.
// for (int i = 0; i < all_sensor_xml.size(); i++) {
// std::cout << "Sensor vector #: " << i << std::endl;

// // Traverse the map
// for (auto itr : all_sensor_xml[i])
// std::cout << "Sensor: 1. " << itr.first << " 2. " << itr.second << std::endl;
// }

return all_sensor_xml;
}

std::vector<std::map<std::string,std::string>> Entity::set_autonomy_xml_vect(){
std::vector<std::map<std::string,std::string>> all_autonomy_xml;
std::map<std::string,std::string> cur_autonomy_xml;

for (AutonomyPtr a : autonomies_) {
cur_autonomy_xml = a->mission_xml_set();
all_autonomy_xml.push_back(cur_autonomy_xml);
}

// Verifies each autonomy has the expected xml specific tags. This can be uncommented for debugging.
// for (int i = 0; i < all_autonomy_xml.size(); i++) {
// std::cout << "Autonomy vector #: " << i << std::endl;

// // Traverse the map
// for (auto itr : all_autonomy_xml[i])
// std::cout << "Autonomy: 1. " << itr.first << " 2. " << itr.second << std::endl;
// }

return all_autonomy_xml;
}

std::vector<std::map<std::string,std::string>> Entity::set_controller_xml_vect(){
std::vector<std::map<std::string,std::string>> all_controller_xml;
std::map<std::string,std::string> cur_controller_xml;

for (ControllerPtr c : controllers_) {
cur_controller_xml = c->mission_xml_set();
all_controller_xml.push_back(cur_controller_xml);
}

// Verifies each controller has the expected xml specific tags. This can be uncommented for debugging.
// for (int i = 0; i < all_controller_xml.size(); i++) {
// std::cout << "Controller vector #: " << i << std::endl;

// // Traverse the map
// for (auto itr : all_controller_xml[i])
// std::cout << "Controller: 1. " << itr.first << " 2. " << itr.second << std::endl;
// }

return all_controller_xml;
}

} // namespace scrimmage
14 changes: 13 additions & 1 deletion src/parse/ConfigParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ bool ConfigParse::parse(const std::map<std::string, std::string> &overrides,
buffer << file.rdbuf();
file.close();
std::string content(buffer.str());
doc.parse<0>(&content[0]);
try {
// Note: This parse function can hard fail (seg fault, no exception) on
// badly formatted xml data. Sometimes it'll except, sometimes not.
// doc.parse<0>(mission_file_content_vec.data());
doc.parse<0>(&content[0]);
}
catch (const rapidxml::parse_error& e)
{
std::cout << e.what() << std::endl;
throw std::runtime_error("Error parsing config file " + filename);
// cout << "scrimmage::MissionParse::parse: Exception during rapidxml::xml_document<>.parse<>()." << endl;
return false;
}

rx::xml_node<> *config_node = doc.first_node("params");
if (config_node == 0) {
Expand Down
Loading