Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Namespace with maliput #4

Merged
merged 11 commits into from
Oct 11, 2021
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

A clone of [`drake`](https://github.com/RobotLocomotion/drake)'s trajectory integration support for `maliput` backends.

## How to copy `drake` into `maliput_drake`?

### Copying files

TBD

### Namespacing

The following transformations are necessary to successfully namespace copied
files:

1. Replace occurrences of `namespace drake` by `namespace maliput::drake`.
2. Replace occurrences of `::drake` by `::maliput::drake`.
3. Replace occurrences of `#include "drake/` by `#include "maliput/drake`.
4. Replace occurrences of `<drake::` by `<maliput::drake`.
5. Replace occurrences of `(drake::` by `(maliput::drake::`.
6. Replace occurrences of ` drake::` by ` maliput::drake`.
7. Replace occurrences of `<::drake` by `<::maliput::drake`.

## Build

1. Setup a maliput_drake (or a wider maliput) development workspace as described [here](https://github.com/ToyotaResearchInstitute/maliput_documentation/blob/main/docs/installation_quickstart.rst).
Expand Down
2 changes: 1 addition & 1 deletion maliput_drake/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(drake)
add_subdirectory(maliput)
1 change: 1 addition & 0 deletions maliput_drake/include/maliput/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(drake)
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static_assert(EIGEN_VERSION_AT_LEAST(3, 3, 4),
// order-of-specialization-includes-changed mistakes.
//
// clang-format off
#include "drake/common/eigen_autodiff_types.h"
#include "drake/common/autodiffxd.h"
#include "drake/common/autodiff_overloads.h"
#include "maliput/drake/common/eigen_autodiff_types.h"
#include "maliput/drake/common/autodiffxd.h"
#include "maliput/drake/common/autodiff_overloads.h"
// clang-format on
#undef DRAKE_COMMON_AUTODIFF_HEADER
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// \endcode{}
///
/// @note The if_then_else and cond functions for AutoDiffScalar are in
/// namespace drake because cond is defined in namespace drake in
/// namespace maliput::drake because cond is defined in namespace maliput::drake in
/// "drake/common/cond.h" file.

#pragma once
Expand All @@ -27,9 +27,9 @@
#include <cmath>
#include <limits>

#include "drake/common/cond.h"
#include "drake/common/drake_assert.h"
#include "drake/common/dummy_value.h"
#include "maliput/drake/common/cond.h"
#include "maliput/drake/common/drake_assert.h"
#include "maliput/drake/common/dummy_value.h"

namespace Eigen {

Expand Down Expand Up @@ -151,7 +151,7 @@ pow(const Eigen::AutoDiffScalar<DerTypeA>& base,

} // namespace Eigen

namespace drake {
namespace maliput::drake {

/// Returns the autodiff scalar's value() as a double. Never throws.
/// Overloads ExtractDoubleOrThrow from common/extract_double.h.
Expand Down Expand Up @@ -216,4 +216,4 @@ cond(bool f_cond, const Eigen::AutoDiffScalar<DerType>& e_then, Rest... rest) {
return if_then_else(f_cond, e_then, cond(rest...));
}

} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "drake/common/autodiff.h"
#include "drake/common/symbolic.h"
#include "maliput/drake/common/autodiff.h"
#include "maliput/drake/common/symbolic.h"

namespace drake {
namespace maliput::drake {

/// Makes the derviatives of the recipient coherent with respect to those of the
/// donor variable (see drake/common/autodiffxd.h). If the recipient's
Expand All @@ -27,4 +27,4 @@ inline void autodiffxd_make_coherent(const double&, double*) {}
inline void autodiffxd_make_coherent(const symbolic::Expression&,
symbolic::Expression*) {}

} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstring>
#include <type_traits>

namespace drake {
namespace maliput::drake {
namespace internal {

/** Implements C++20 https://en.cppreference.com/w/cpp/numeric/bit_cast (but
Expand All @@ -22,4 +22,4 @@ To bit_cast(const From& from) noexcept {
}

} // namespace internal
} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <functional>
#include <type_traits>

#include "drake/common/double_overloads.h"
#include "maliput/drake/common/double_overloads.h"

namespace drake {
namespace maliput::drake {
/** @name cond
Constructs conditional expression (similar to Lisp's cond).

Expand Down Expand Up @@ -41,4 +41,4 @@ ScalarType cond(const decltype(ScalarType() < ScalarType()) & f_cond,
return if_then_else(f_cond, e_then, cond(rest...));
}
///@}
} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

namespace drake {
namespace maliput::drake {

constexpr int kQuaternionSize = 4;

Expand All @@ -18,4 +18,4 @@ const int kRotmatSize = kSpaceDimension * kSpaceDimension;

enum class ToleranceType { kAbsolute, kRelative };

} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
#include <memory>
#include <utility>

#include "drake/common/drake_assert.h"
#include "maliput/drake/common/drake_assert.h"

namespace drake {
namespace maliput::drake {

// TODO(SeanCurtis-TRI): Consider extending this to add the Deleter as well.
/** A smart pointer with deep copy semantics.
Expand All @@ -35,7 +35,7 @@ namespace drake {
`friend copyable_unique_ptr<Foo>;` appears in Foo's class declaration.

<!-- Developer note: if you change or extend the definition of an acceptable
clone method here, be sure to consider whether drake::is_cloneable should
clone method here, be sure to consider whether maliput::drake::is_cloneable should
be changed as well. -->

Generally, the API is modeled as closely as possible on the C++ standard
Expand Down Expand Up @@ -351,7 +351,7 @@ class copyable_unique_ptr : public std::unique_ptr<T> {
// copyable_unique_ptr class so that they have the same method access as
// the class does. That way we can use them to determine whether
// copyable_unique_ptr can get access. That precludes using helper classes
// like drake::is_cloneable because those may have different access due to an
// like maliput::drake::is_cloneable because those may have different access due to an
// explicit friend declaration giving copyable_unique_ptr<Foo> access to Foo's
// private business. The static_assert below ensures that at least one of
// these must return true.
Expand Down Expand Up @@ -440,4 +440,4 @@ std::basic_ostream<charT, traits>& operator<<(
return os;
}

} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "drake/common/autodiff.h"
#include "drake/common/symbolic.h"
#include "maliput/drake/common/autodiff.h"
#include "maliput/drake/common/symbolic.h"

// N.B. `CommonScalarPack` and `NonSymbolicScalarPack` in `systems_pybind.h`
// should be kept in sync with this file.
Expand All @@ -12,13 +12,13 @@
/// Similar to the Eigen library, many classes in Drake use a template argument
/// to specify the numeric scalar type to use for computation. We typically
/// name that template argument <b>`<T>`</b>. For an example, see the class
/// drake::math::RigidTransform.
/// maliput::drake::math::RigidTransform.
///
/// Most scalar-templated classes in Drake only support a small, fixed set of
/// scalar types:
/// - `double` (always)
/// - drake::AutoDiffXd (almost always)
/// - drake::symbolic::Expression (sometimes)
/// - maliput::drake::AutoDiffXd (almost always)
/// - maliput::drake::symbolic::Expression (sometimes)
///
/// When Drake documentation refers to "default scalars", it means all three
/// of the types above.
Expand Down Expand Up @@ -49,11 +49,11 @@
///
/// Example `my_system.h`:
/// @code
/// #include "drake/common/default_scalars.h"
/// #include "maliput/drake/common/default_scalars.h"
///
/// namespace sample {
/// template <typename T>
/// class MySystem final : public drake::systems::LeafSystem<T> {
/// class MySystem final : public maliput::drake::systems::LeafSystem<T> {
/// ...
/// };
/// } // namespace sample
Expand All @@ -78,32 +78,32 @@
#define DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( \
SomeType) \
template SomeType<double>; \
template SomeType<::drake::AutoDiffXd>; \
template SomeType<::drake::symbolic::Expression>;
template SomeType<::maliput::drake::AutoDiffXd>; \
template SomeType<::maliput::drake::symbolic::Expression>;

/// Defines template instantiations for Drake's default nonsymbolic scalars.
/// This should only be used in .cc files, never in .h files.
#define \
DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( \
SomeType) \
template SomeType<double>; \
template SomeType<::drake::AutoDiffXd>;
template SomeType<::maliput::drake::AutoDiffXd>;

/// Declares that template instantiations exist for Drake's default scalars.
/// This should only be used in .h files, never in .cc files.
#define DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( \
SomeType) \
extern template SomeType<double>; \
extern template SomeType<::drake::AutoDiffXd>; \
extern template SomeType<::drake::symbolic::Expression>;
extern template SomeType<::maliput::drake::AutoDiffXd>; \
extern template SomeType<::maliput::drake::symbolic::Expression>;

/// Declares that template instantiations exist for Drake's default nonsymbolic
/// scalars. This should only be used in .h files, never in .cc files.
#define \
DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( \
SomeType) \
extern template SomeType<double>; \
extern template SomeType<::drake::AutoDiffXd>;
extern template SomeType<::maliput::drake::AutoDiffXd>;

/// @}

Expand All @@ -120,7 +120,7 @@ extern template SomeType<::drake::AutoDiffXd>;
///
/// Example `example.h`:
/// @code
/// #include "drake/common/default_scalars.h"
/// #include "maliput/drake/common/default_scalars.h"
///
/// namespace sample {
///
Expand Down Expand Up @@ -203,8 +203,8 @@ constexpr auto Make_Function_Pointers_Pack1() { \
static constexpr auto Function_Femplates __attribute__((used)) = \
Make_Function_Pointers_Pack1< \
double, \
::drake::AutoDiffXd, \
::drake::symbolic::Expression>();
::maliput::drake::AutoDiffXd, \
::maliput::drake::symbolic::Expression>();

/// Defines template instantiations for Drake's default nonsymbolic scalars.
/// This should only be used in .cc files, never in .h files.
Expand All @@ -226,6 +226,6 @@ constexpr auto Make_Function_Pointers_Nonsym_Pack1() { \
static constexpr auto Function_Templates_Nonsym __attribute__((used)) = \
Make_Function_Pointers_Nonsym_Pack1< \
double, \
::drake::AutoDiffXd>();
::maliput::drake::AutoDiffXd>();

/// @}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

namespace drake {
namespace maliput::drake {
/// Provides if-then-else expression for double. The value returned by the
/// if-then-else expression is @p v_then if @p f_cond is @c true. Otherwise, it
/// returns @p v_else.
Expand All @@ -18,4 +18,4 @@ inline double if_then_else(bool f_cond, double v_then, double v_else) {
return f_cond ? v_then : v_else;
}

} // namespace drake
} // namespace maliput::drake
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/// This header will define exactly one of either @p DRAKE_ASSERT_IS_ARMED or
/// @p DRAKE_ASSERT_IS_DISARMED to indicate whether @p DRAKE_ASSERT is armed.
///
/// This header will define both `constexpr bool drake::kDrakeAssertIsArmed`
/// and `constexpr bool drake::kDrakeAssertIsDisarmed` globals.
/// This header will define both `constexpr bool maliput::drake::kDrakeAssertIsArmed`
/// and `constexpr bool maliput::drake::kDrakeAssertIsDisarmed` globals.
///
/// One difference versus the standard @p assert(condition) is that the
/// @p condition within @p DRAKE_ASSERT is always syntax-checked, even if
Expand Down Expand Up @@ -80,7 +80,7 @@
# define DRAKE_ASSERT_IS_ARMED
#endif

namespace drake {
namespace maliput::drake {
namespace internal {
// Abort the program with an error message.
[[noreturn]] void Abort(const char* condition, const char* func,
Expand All @@ -103,29 +103,29 @@ struct ConditionTraits {
}
};
} // namespace assert
} // namespace drake
} // namespace maliput::drake

#define DRAKE_UNREACHABLE() \
::drake::internal::Abort( \
::maliput::drake::internal::Abort( \
"Unreachable code was reached?!", __func__, __FILE__, __LINE__)

#define DRAKE_DEMAND(condition) \
do { \
typedef ::drake::assert::ConditionTraits< \
typedef ::maliput::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>> Trait; \
static_assert(Trait::is_valid, "Condition should be bool-convertible."); \
if (!Trait::Evaluate(condition)) { \
::drake::internal::AssertionFailed( \
::maliput::drake::internal::AssertionFailed( \
#condition, __func__, __FILE__, __LINE__); \
} \
} while (0)

#ifdef DRAKE_ASSERT_IS_ARMED
// Assertions are enabled.
namespace drake {
namespace maliput::drake {
constexpr bool kDrakeAssertIsArmed = true;
constexpr bool kDrakeAssertIsDisarmed = false;
} // namespace drake
} // namespace maliput::drake
# define DRAKE_ASSERT(condition) DRAKE_DEMAND(condition)
# define DRAKE_ASSERT_VOID(expression) do { \
static_assert( \
Expand All @@ -135,12 +135,12 @@ constexpr bool kDrakeAssertIsDisarmed = false;
} while (0)
#else
// Assertions are disabled, so just typecheck the expression.
namespace drake {
namespace maliput::drake {
constexpr bool kDrakeAssertIsArmed = false;
constexpr bool kDrakeAssertIsDisarmed = true;
} // namespace drake
} // namespace maliput::drake
# define DRAKE_ASSERT(condition) static_assert( \
::drake::assert::ConditionTraits< \
::maliput::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>>::is_valid, \
"Condition should be bool-convertible.");
# define DRAKE_ASSERT_VOID(expression) static_assert( \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdexcept>
#include <string>

namespace drake {
namespace maliput::drake {
namespace internal {

// This is what DRAKE_ASSERT and DRAKE_DEMAND throw when our assertions are
Expand All @@ -15,4 +15,4 @@ class assertion_error : public std::runtime_error {
};

} // namespace internal
} // namespace drake
} // namespace maliput::drake
Loading