Skip to content
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
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# SCRIMMAGE Multi-Agent Simulator

[![Build Status](https://travis-ci.org/gtri/scrimmage.png?branch=master)](https://travis-ci.org/gtri/scrimmage)
[![CI](https://github.com/gtri/scrimmage/actions/workflows/ubuntu-24.04.yml/badge.svg)](https://github.com/gtri/scrimmage/actions/workflows/ubuntu-24.04.yml)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/gtri/scrimmage/issues)
[![Docker Pulls](https://img.shields.io/docker/pulls/syllogismrxs/scrimmage.svg?maxAge=2592000)](https://hub.docker.com/r/syllogismrxs/scrimmage)
[![Join the chat at https://gitter.im/gtri-scrimmage/community](https://badges.gitter.im/gtri-scrimmage/community.svg)](https://gitter.im/gtri-scrimmage/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Docker Pulls](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fghcr-badge.elias.eu.org%2Fapi%2Fgtri%2Fscrimmage%2Fscrimmage-24.04&query=downloadCount&label=Docker%20Pulls)](ghcr.io/gtri/scrimmage-24.04:latest)

![SCRIMMAGE Logo](./docs/source/images/scrimmage_vert_black_clean_medium.png)

Expand Down Expand Up @@ -222,15 +221,15 @@ The SCRIMMAGE docker image is pushed to a public repository after a successful
build on Travis. If docker is installed on your machine, you can obtain the
SCRIMMAGE docker image by running the following command:

docker pull syllogismrxs/scrimmage:latest
docker pull ghcr.io/gtri/scrimmage-24.04:latest

You can pass mission files from your host machine to the `scrimmage` executable
inside of the docker container with the following command:

cd /path/to/scrimmage/missions
docker run --name my-scrimmage \
-v ${PWD}/straight_jsbsim.xml:/straight_jsbsim.xml \
syllogismrxs/scrimmage:latest /straight_jsbsim.xml
ghcr.io/gtri/scrimmage-24.04:latest /straight_jsbsim.xml

The previous command mounts the `straight_jsbsim.xml` mission file on your host
machine into the scrimmage container and then the `/straight_jsbsim.xml`
Expand All @@ -246,7 +245,7 @@ log files from the docker container:
If you need to drop into a shell inside of the scrimmage container, you will
need to overwrite the docker image's ENTRYPOINT.

docker run -it --entrypoint="/bin/bash" syllogismrxs/scrimmage:latest
docker run -it --entrypoint="/bin/bash" ghcr.io/gtri/scrimmage-24.04:latest

Once inside of the container, you will need to source the `setup.bash` file
manually before running a mission.
Expand All @@ -259,18 +258,18 @@ If you want to see the scrimmage mission on your host, you can do the following:
1. Allow docker to connect to your local display
2. Run the mission in the docker container

xhost +local:docker
docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix scrimmage/ubuntu:latest
source ~/.scrimmage/setup.bash
scrimmage ~/scrimmage/scrimmage/missions/straight.xml
xhost +local:docker
docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix scrimmage/ubuntu:latest
source ~/.scrimmage/setup.bash
scrimmage ~/scrimmage/scrimmage/missions/straight.xml

If you want gpu access for your docker container You must do the following:

1. Install the container tools for your OS/GPU to allow the container to access your host's resources properly.
a. For NVidia GPUS this is the [Nvidia container toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
a. For Nvidia GPUs this is the [Nvidia container toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
2. include the --gpus all flag in your docker run invocation

docker run -it --gpus all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix scrimmage/ubuntu:latest
docker run -it --gpus all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix scrimmage/ubuntu:latest

## Building SCRIMMAGE for CentOS or RedHat

Expand Down
8 changes: 4 additions & 4 deletions docs/source/overview/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ Print out the data from the CSV file:
:linenos:

for (int r = 0; r < csv.rows(); r++) {
cout << "t: " << csv.at(r, "t") << endl;
cout << "x: " << csv.at(r, "x") << endl;
cout << "y: " << csv.at(r, "y") << endl;
cout << "z: " << csv.at(r, "z") << endl;
cout << "t: " << csv.at<double>(r, "t") << endl;
cout << "x: " << csv.at<double>(r, "x") << endl;
cout << "y: " << csv.at<double>(r, "y") << endl;
cout << "z: " << csv.at<double>(r, "z") << endl;
}

Real-time Plotting from CSV
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ During the simulation, another plugin can call the ``set_param()`` function:

set_param<double>("desired_z", 100.0)

while will have the affect of directly modifying the value of ``desired_z_`` in
which will have the affect of directly modifying the value of ``desired_z_`` in
the plugin that registered that parameter. If you require a callback function
when the parameter value is updated, you can use the optional callback form of
the ``register_param()`` function:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mission level functionality. A sample can be found in
if (!summary_found) return;

const int row = csv.rows() - 1;
double collisions = csv.at(row, "team_coll");
double collisions = csv.at<int>(row, "team_coll");
EXPECT_GT(collisions, 0); // expect collisions
}

Expand Down Expand Up @@ -71,5 +71,5 @@ that there was at least one collision in the simulation by reading the
if (!summary_found) return;

const int row = csv.rows() - 1;
double collisions = csv.at(row, "team_coll");
double collisions = csv.at<int>(row, "team_coll");
EXPECT_GT(collisions, 0); // expect collisions
53 changes: 47 additions & 6 deletions include/scrimmage/common/CSV.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,56 @@
#define INCLUDE_SCRIMMAGE_COMMON_CSV_H_

#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <variant>

#include "scrimmage/parse/ParseUtils.h"

namespace {

struct StringifyVisitor {

bool double_is_fixed = true;
bool double_is_scientific = true;
int double_precision = 13;

std::string operator()(bool value) const { return value ? "true" : "false"; }
std::string operator()(uint32_t value) const { return std::to_string(value); }
std::string operator()(uint64_t value) const { return std::to_string(value); }
std::string operator()(int32_t value) const { return std::to_string(value); }
std::string operator()(int64_t value) const { return std::to_string(value); }
std::string operator()(const std::string& value) const { return value; }
std::string operator()(double value) const {
// default precision values for double are not enough in many cases
std::ostringstream conv;
if (double_is_fixed) {
conv << std::fixed;
}
if (double_is_scientific) {
conv << std::scientific;
}
conv << std::setprecision(double_precision) << value;
return conv.str();
}
};

} // namespace

namespace scrimmage {

class CSV {
public:
typedef std::list<std::string> Headers;
typedef std::list<std::pair<std::string, double>> Pairs;
typedef std::vector<std::string> Headers;
typedef std::variant<bool, uint32_t, uint64_t, int32_t, int64_t, std::string, double>
PossibleVariantTypes;
typedef std::vector<std::pair<std::string, PossibleVariantTypes>> Pairs;

~CSV();

Expand Down Expand Up @@ -75,7 +113,11 @@ class CSV {

size_t rows();

double at(int row, const std::string& header);
template <class T1>
T1 at(int row, const std::string& header) {
const int column = column_headers_.at(header);
return convert<T1>(table_.at(row).at(column));
}

friend std::ostream& operator<<(std::ostream& os, const CSV& csv);

Expand All @@ -87,7 +129,7 @@ class CSV {
void set_double_scientific(bool is_scientific) { double_is_scientific_ = is_scientific; }

protected:
std::list<std::string> get_csv_line_elements(const std::string& str);
std::string get_csv_string(const PossibleVariantTypes& val) const;

void write_headers();

Expand All @@ -100,7 +142,7 @@ class CSV {
// Key 1 : Row Index
// Key 2 : Column Index
// Value : Cell Value
std::map<int, std::map<int, double>> table_;
std::map<int, std::map<int, std::string>> table_;
int next_row_ = 0;

std::ofstream file_out_;
Expand All @@ -110,7 +152,6 @@ class CSV {
int double_precision_ = 13;
bool double_is_fixed_ = true;
bool double_is_scientific_ = false;

std::string headers_to_string() const;
std::string rows_to_string() const;
std::string row_to_string(const int& i) const;
Expand Down
Loading