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 documentation for installation and python module #27

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (${BUILD_PYTHON_BINDINGS})
FILE(COPY carma_clock_py/python_wrapper_test.py DESTINATION .)
add_test(NAME test_carma_clock_python_module_binding COMMAND ${PYTHON_EXECUTABLE} python_wrapper_test.py )
# set cpack depedencies
set(CPACK_DEBIAN_PACKAGE_DEPENDS carma-clock-1 python3-dev)
set(CPACK_DEBIAN_PACKAGE_DEPENDS python3-dev)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something I noticed. This is the carma-clock-1 package. It can't depend on itself

# remove debug post fix for library. Required due to import naming for python module import
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "")
endif()
Expand Down
87 changes: 70 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,82 @@

The CARMA Time Library is a focused library providing classes and utilities which enable a consuming project to synchronize mock time with the CARMA simulation framework.

# CI Status
## CI Status

These badges are for the default branch only.

[![Build Workflow](https://github.com/usdot-fhwa-stol/carma-time-lib/actions/workflows/build.yml/badge.svg)](https://github.com/usdot-fhwa-stol/carma-time-lib/actions/workflows/build.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=usdot-fhwa-stol_carma-time-lib&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=usdot-fhwa-stol_carma-time-lib)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=usdot-fhwa-stol_carma-time-lib&metric=coverage)](https://sonarcloud.io/summary/new_code?id=usdot-fhwa-stol_carma-time-lib)

## Using the Library

The following sections will describe how to use the CARMA Time Library in you C++ or Python application
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved

### Install library

The easiest way to include the CARMA Time Library in your application is to install it via `apt`.
**Prerequisites**

- Ubuntu ( jammy, focal, bionic )
- CMake 3.10
- Python 3
The CARMA Time library is one the the FHWA (Federal Highway Administration) STOL (Saxton Transportation Operation Library) libraries build into a Debian package via CMake/CPack scripts from the [carma-builds](https://github.com/usdot-fhwa-stol/carma-builds) repository. CI (Continuous Integration) scrips also push this Debain package to a STOL Debian Package repository. To install this package you must only add this repository to `apt`.
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
```
# Get ubuntu distribution code name. All STOL APT debian packages are pushed to S3 bucket based on distribution codename.
. /etc/lsb-release
# add the STOL APT repository
echo "deb [trusted=yes] http://s3.amazonaws.com/stol-apt-repository ${DISTRIB_CODENAME} main" > /etc/apt/sources.list.d/stol-apt-repository.list
Copy link
Contributor

Choose a reason for hiding this comment

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

When I run this command, it shows this:

echo "deb [trusted=yes] http://s3.amazonaws.com/stol-apt-repository ${DISTRIB_CODENAME} main" > /etc/apt/sources.list.d/stol-apt-repository.list
bash: /etc/apt/sources.list.d/stol-apt-repository.list: Permission denied

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with sudo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you may need to go sudo -i and then run it.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh you are right. can we include that for dummies like me

apt update
apt install carma-clock-1
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
```
This steps above add the relavent STOL apt repository for pulling correct debian package.

### Including with CMake (C++)
To find and link this library via CMake the following commands are necessary

```cmake
cmake_minimum_required(VERSION 3.10.2)
...
# This can be set inside CMake files or via argument passed to cmake CLI calls
list(APPEND CMAKE_MODULE_PATH "/opt/carma/cmake")
...
# Find CMake package
find_package(carma-clock REQUIRED)
...
# Link against library
target_link_libraries( ${PROJECT_NAME} PUBLIC
::carma-clock

)
```

### Importing as Python Module
> [!IMPORTANT]\
>Python module support is currently only available for x86/amd devices
To import this library as a python module the following is necessary

```python
# This path can be added via the sys module or by directly appending the PYTHON_PATH environment variable.
import sys
sys.path.append('/opt/carma/lib/')
# Import module
import libcarma_clock
...
# Initialize CARMA Clock object
clock = libcarma_clock.CarmaClock(False)

```

## Configuration

The following operating modes are available in the library:
* Real-time
* Simulated time

TODO How the library is configured

TODO Move this configuration logic into a time manager tool in a separate library.
Comment on lines +81 to +83
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we planning to address TODO in this PR or leave for next?

Copy link
Contributor Author

@paulbourelly999 paulbourelly999 Jun 6, 2024

Choose a reason for hiding this comment

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

Not in here. Not even sure what Rob was referring to with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, then should we just remove it.

# Architecture

The CarmaClock class contains an internal representation for time which serves as a replacement for the epoch tracked by the system clock, or any other related time-keeping machinery.
Expand Down Expand Up @@ -72,22 +141,6 @@ Some additional configurations are provided out-of-the-box to streamline the dev
| install_dependencies.sh | Docker Dev Environment internal script. TODO move this file? | | | |
| .vscode/tasks.json | Build task definition utilizing Docker Dev Environment. | | | |

## Deploying
TODO
# Using the Library
## Dependency Management
TODO
## Linking Against the Library
TODO
## Configuration

The following operating modes are available in the library:
* Real-time
* Simulated time

TODO How the library is configured

TODO Move this configuration logic into a time manager tool in a separate library.

# CARMA Projects

Expand Down
121 changes: 4 additions & 117 deletions carma_clock_py/README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,5 @@
# CARMA Time Library
# CARMA Clock Python Module
This directory includes the source files for building the CARMA Clock Python Module bindings with [pybind11](https://pybind11.readthedocs.io/en/stable/). It includes a `src/carma_clock-py.cpp` file which calls the pybind11 library functions/macros to build python module bindings and a `/cmake/dependencies.cmake` file which pulls in pybind11 and finds python3 for CMake. It also includes a CMake test for which runs the `python_wrapper.test.py` to ensure the resulting library built can be imported as a python module.
## Dependencies
The CMake dependencies script relies on [CPM](https://github.com/cpm-cmake/CPM.cmake) and Python3 to be installed and discoverable to CMake.

The CARMA Time Library is a focused library providing classes and utilities which enable a consuming project to synchronize mock time with the CARMA simulation framework.

# CI Status

These badges are for the default branch only.

[![Build Workflow](https://github.com/usdot-fhwa-stol/carma-time-lib/actions/workflows/build.yml/badge.svg)](https://github.com/usdot-fhwa-stol/carma-time-lib/actions/workflows/build.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=usdot-fhwa-stol_carma-time-lib&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=usdot-fhwa-stol_carma-time-lib)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=usdot-fhwa-stol_carma-time-lib&metric=coverage)](https://sonarcloud.io/summary/new_code?id=usdot-fhwa-stol_carma-time-lib)
# Architecture

The CarmaClock class contains an internal representation for time which serves as a replacement for the epoch tracked by the system clock, or any other related time-keeping machinery.

This internal time value is stored as a TODO value representing TODO since TODO.

The framework provides the following capabilities:
1. Initialization and update functions which set the internal time representation mode and value.
2. Current time available for query.
3. Time representation available in real-time and simulation mode.
4. The framework falls back to system time if not running in simulation mode.
5. Utility functions.

# Building the Library
## Configuring Build Environment

The project build environment is supplied as a single-image [Docker Dev Environment](https://docs.docker.com/desktop/dev-environments/), with Visual Studio Code editor configurations to enable streamlined setup.

To load the project in VSCode:

1. Clone this repository.

```
git clone git@github.com:usdot-fhwa-stol/carma-time-lib.git
cd carma-time-lib/
```

2. Open the VSCode editor.
3. Open the cloned project folder.
4. Accept the **Reopen in Container** prompt for **"Folder contains a Dev Container configuration file. Reopen folder to develop in a container (learn more)."**

![Dev Container Rebuild Notification](doc/images/DevContainerRebuildNotification.png)

7. If that prompt did not appear, open the **View > Command Palette** and type to locate **"Dev Containers: Rebuild and Reopen in Container"**.
6. The editor should refresh and display the updated activity in the command line.

![Dev Container Rebuild Log](doc/images/DevContainerRebuildLog.png)

If the container startup was successful, the development environment is up and running and contains the library dependencies and compilation environment. It is possible to proceed with the build.

## Building

1. In VSCode, open **Build the Terminal > Run Build Task...**.

![Library Build Log](doc/images/LibraryBuildLog.png)

2. If the build is successful, tests are automatically executed and a Debian package is generated.
3. TODO more details (output product locations, reference information for generalized docker dev solution including container configured locations etc.).

## Additional IDE Configuration

Some additional configurations are provided out-of-the-box to streamline the developer's setup process. These are included for Visual Studio Code:

| Item | Description |
|---------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| .devcontainer/devcontainer.json | Docker Dev Environment definition file. | | | |
| .editorconfig | Some standard, robust VSCode editor configurations. | | | |
| .github/workflows/build.yml | GitHub CI build definition. | | | |
| .github/workflows/sonar-scanner.yml | TODO | | | |
| .gitignore | Some helpful Git Ignore rules that should apply to Cmake-based C++ projects developed with most modern code editors. | | | |
| install_dependencies.sh | Docker Dev Environment internal script. TODO move this file? | | | |
| .vscode/tasks.json | Build task definition utilizing Docker Dev Environment. | | | |

## Deploying
TODO
# Using the Library
## Dependency Management
TODO
## Linking Against the Library
TODO
## Configuration

The following operating modes are available in the library:
* Real-time
* Simulated time

TODO How the library is configured

TODO Move this configuration logic into a time manager tool in a separate library.

# CARMA Projects

See all CARMA projects in the [USDOT FHWA STOL](https://github.com/usdot-fhwa-stol) organization on GitHub.

In particular, the CARMA Simulation framework is available [here](https://github.com/usdot-fhwa-stol/carma-simulation).

## Contribution

Welcome to the CARMA contributing guide. Please read this guide to learn about our development process, how to propose pull requests and improvements, and how to build and test your changes to this project. [CARMA Contributing Guide](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)

## Code of Conduct

Please read our [CARMA Code of Conduct](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Code_of_Conduct.md) which outlines our expectations for participants within the CARMA community, as well as steps to reporting unacceptable behavior. We are committed to providing a welcoming and inspiring community for all and expect our code of conduct to be honored. Anyone who violates this code of conduct may be banned from the community.

## Attribution

The development team would like to acknowledge the people who have made direct contributions to the design and code in this repository. [CARMA Attribution](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/ATTRIBUTION.md)

## License

By contributing to the Federal Highway Administration (FHWA) Connected Automated Research Mobility Applications (CARMA), you agree that your contributions will be licensed under its Apache License 2.0 license. [CARMA License](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/docs/License.md)

## Contact

Please click on the CARMA logo below to visit the Federal Highway Adminstration(FHWA) CARMA website.

[![CARMA Image](https://raw.githubusercontent.com/usdot-fhwa-stol/CARMAPlatform/develop/docs/image/CARMA_icon.png)](https://highways.dot.gov/research/research-programs/operations/CARMA)
24 changes: 17 additions & 7 deletions carma_clock_py/src/carma_clock_py.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#include <pybind11/pybind11.h>

#include <string>
#include <carma_clock.h>
namespace py = pybind11;

PYBIND11_MODULE(libcarma_clock, m) {
PYBIND11_MODULE(libcarma_clock, m)
{
m.doc() = R"(CARMA Time Module provides the CarmaClock object, which is a
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New module documentation string.

wrapper for direct calls to system time. It is intended for use when it is
necessary to have control over each increment in time. An example of a use
case is in a simulation environment where time may progress non-linearly.
The CarmaClock constructor takes a boolean parameter to indicate whether
to directlzy make calls to system time or to use its internal store value
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in directlzy

for time. Calls to its update() method will update the internal stored value,
while calls to its now* or sleep* will return or unblock threads depending
on the stored value respectively.)";

py::class_<fwha_stol::lib::time::CarmaClock>(m, "CarmaClock")
.def(py::init<bool>(), py::arg("simulation_mode")=false)
.def(py::init<bool>(), py::arg("simulation_mode") = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

optional, but apparently we can also add method documentation like this

    py::class_<fwha_stol::lib::time::CarmaClock>(m, "CarmaClock")
        .def(py::init<bool>(), py::arg("simulation_mode") = false)
        .def("nowInSeconds", &fwha_stol::lib::time::CarmaClock::nowInSeconds, "Get current time in seconds.")
        .def("nowInMilliseconds", &fwha_stol::lib::time::CarmaClock::nowInMilliseconds, "Get current time in milliseconds.")
        .def("update", &fwha_stol::lib::time::CarmaClock::update, py::arg("current_time"), "Update the internal clock with the current time.")
        .def("is_simulation_mode", &fwha_stol::lib::time::CarmaClock::is_simulation_mode, "Check if in simulation mode.")
        .def("wait_for_initialization", &fwha_stol::lib::time::CarmaClock::wait_for_initialization, "Wait for initialization to complete ??? what does it actually do???")
        .def("sleep_until", &fwha_stol::lib::time::CarmaClock::sleep_until, py::arg("future_time"), "Sleep until a specified future time. ??? does ms or s matter here???")
        .def("sleep_for", &fwha_stol::lib::time::CarmaClock::sleep_for, py::arg("time_to_sleep"), "Sleep for a specified duration ??? ms or s ???.");

.def("nowInSeconds", &fwha_stol::lib::time::CarmaClock::nowInSeconds)
.def("nowInMilliseconds", &fwha_stol::lib::time::CarmaClock::nowInMilliseconds)
.def("update", &fwha_stol::lib::time::CarmaClock::update, py::arg("current_time"))
.def("is_simulation_mode", &fwha_stol::lib::time::CarmaClock::is_simulation_mode)
.def("wait_for_initialization",&fwha_stol::lib::time::CarmaClock::wait_for_initialization)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formatting changes

.def("sleep_until",&fwha_stol::lib::time::CarmaClock::sleep_until, py::arg("future_time"))
.def("sleep_for",&fwha_stol::lib::time::CarmaClock::sleep_for, py::arg("time_to_sleep"));

.def("wait_for_initialization", &fwha_stol::lib::time::CarmaClock::wait_for_initialization)
.def("sleep_until", &fwha_stol::lib::time::CarmaClock::sleep_until, py::arg("future_time"))
.def("sleep_for", &fwha_stol::lib::time::CarmaClock::sleep_for, py::arg("time_to_sleep"));
}
Loading