Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed May 24, 2024
1 parent 1924f68 commit 863869d
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 27 deletions.
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ project(carma_clock
VERSION 0.0.1
LANGUAGES CXX
)
include(cmake/dependencies.cmake)

include(cmake/dependencies.cmake)
add_library(${PROJECT_NAME} SHARED )

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
target_link_libraries( ${PROJECT_NAME} PUBLIC
Python3::Python
pybind11::module

)
# Strip library name and add extension
pybind11_strip(${PROJECT_NAME})
pybind11_extension(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION 1
)

include(CommonSource)
if (DEFINED ENV{BUILD_ARCHITECTURE})
if ($ENV{BUILD_ARCHITECTURE} STREQUAL "x64")
message(STATUS "Building Python Module binding only supported for x64 builds...")
add_subdirectory(carma_clock_py)
else()
message(STATUS "Building Python Module binding NOT supported for " ${BUILD_ARCHITECTURE} " builds...")
endif()
else()
message(STATUS "Enviroment variable for BUILD_ARCHITECTURE is not set. Skipping Python Module binding ")
endif()

# message(STATUS "Building Python Module binding only supported for x64 builds...")
include(Testing)
#Test for Python inclusion
enable_testing()
FILE(COPY python_wrapper_test.py DESTINATION .)
ADD_TEST(NAME python_wrapper_test COMMAND ${PYTHON_EXECUTABLE} python_wrapper_test.py)
include(CodeCoverage)
include(InstallingGeneral)
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "")
include(InstallingConfigs)
include(Packing)


37 changes: 37 additions & 0 deletions carma_clock_py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.10.2)

# where to find our CMake modules
set(CMAKE_MODULE_PATH "$ENV{CARMA_OPT_DIR}/cmake")


project(carma_clock_py
DESCRIPTION "CARMA time library Python Module"
HOMEPAGE_URL https://github.com/usdot-fhwa-stol/carma-time-lib
VERSION 0.0.1
LANGUAGES CXX
)

include(cmake/dependencies.cmake)
pybind11_add_module(${PROJECT_NAME} SHARED src/carma_clock_py )

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
target_link_libraries( ${PROJECT_NAME} PUBLIC
Python3::Python
pybind11::module
carma_clock

)

set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION 1
)

#Test for Python inclusion
FILE(COPY python_wrapper_test.py DESTINATION .)
add_custom_target(test_carma_clock_python_module_binding ALL COMMAND ${PYTHON_EXECUTABLE} python_wrapper_test.py DEPENDS ${PROJECT_NAME})



118 changes: 118 additions & 0 deletions carma_clock_py/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# CARMA Time Library

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 [email protected]: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)
15 changes: 15 additions & 0 deletions carma_clock_py/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
include(GetCPM)
set(CPM_USE_LOCAL_PACKAGES ON)
set(PYBIND11_INSTALL ON)
set(PYBIND11_TEST OFF)
CPMAddPackage(
NAME pybind11
GITHUB_REPOSITORY pybind/pybind11
SYSTEM ON
GIT_TAG v2.12.0
OPTIONS
"PYBIND11_INSTALL ON"
"PYBIND11_TEST OFF"
)

10 changes: 5 additions & 5 deletions python_wrapper_test.py → carma_clock_py/python_wrapper_test.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#!/usr/bin/python3
import unittest
import carma_clock
import carma_clock_py
import time

"""Test Case for testing basic CarmaClock functionality in python
"""
class TestCarmaClock(unittest.TestCase):

def testSimClockInitializeException(self):
sim_clock = carma_clock.CarmaClock(True)
sim_clock = carma_clock_py.CarmaClock(True)
with self.assertRaises(ValueError) as e:
sim_clock.nowInMilliseconds()

self.assertIn('Clock is not initialized!',str(e.exception))

def testRealClockTime(self):
clock = carma_clock.CarmaClock()
clock = carma_clock_py.CarmaClock()
self.assertAlmostEqual(time.time()*1000, clock.nowInMilliseconds(),delta=10)

def testSimClockUpdate(self):
sim_clock = carma_clock.CarmaClock(True)
sim_clock = carma_clock_py.CarmaClock(True)
sim_clock.update(100)
self.assertEqual(100, sim_clock.nowInMilliseconds())
sim_clock.update(1500)
self.assertEqual(1500, sim_clock.nowInMilliseconds())

if __name__ == '__main__':
unittest.main()
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <pybind11/pybind11.h>

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

PYBIND11_MODULE(carma_clock, m) {
PYBIND11_MODULE(carma_clock_py, m) {
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)
Expand All @@ -14,4 +14,4 @@ PYBIND11_MODULE(carma_clock, m) {
.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"));

}
}
5 changes: 1 addition & 4 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
find_package(Threads)
find_package(Python3 COMPONENTS Interpreter Development)
include(GetCPM)
set(CPM_USE_LOCAL_PACKAGES ON)
CPMAddPackage("gh:pybind/pybind11#v2.12.0")

9 changes: 7 additions & 2 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/sh

set -x
set -ex
# Get ubuntu distribution code name. All STOL APT debian packages are pushed to S3 bucket based on distribution codename.
/opt/carma/scripts/install_dependencies_script.sh python3-dev
echo "BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE}"
if [[ "${BUILD_ARCHITECTURE}" == "x64" ]]; then
/opt/carma/script/install_dependencies_script.sh python3-dev
else
echo "NOTE: Python module support currently only exists for x64 builds. Only building C++ library ... "
fi

0 comments on commit 863869d

Please sign in to comment.