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

Nav2 compatible #51

Merged
merged 7 commits into from
Aug 11, 2024
Merged
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
12 changes: 10 additions & 2 deletions docs/first-steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,25 @@ published sensor topics.
Move it
------------

If you are running MVSim as a ROS node, you can launch any standard teleoperation node
If you are running MVSim as a ROS node, you can launch any standard teleoperation node
and send motion commands to ``/cmd_vel`` as with any other robot or simulator.

If you want to use the teleop panel in rviz2, please install `visualization_tutorials <https://github.com/ros-visualization/visualization_tutorials/tree/ros2>`_.

.. code-block:: bash

cd ros2_ws/src
git clone -b ros2 https://github.com/ros-visualization/visualization_tutorials
colcon build --symlink-install

Additionally, MVSim allows you to **move the robot directly using the keyboard or a joystick**.
Make sure of giving the focus to the MVSim window first,
then use these keys:

- ``w/s`` to increase/decrease the PI controller setpoint linear speed, and
- ``a/d`` to change the corresponding angular speed, that is, rotate to the left and right.
- Use the spacebar as a brake.
- In worlds with more than one robot, select the active robot by pressing the numeric
- In worlds with more than one robot, select the active robot by pressing the numeric
keys ``1``, ``2``, etc.

All the details on **keyboard and joystick-based control** are listed `here <teleoperation.html>`_.
Expand Down
2 changes: 1 addition & 1 deletion formatter.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# formatter.sh
find mvsim_node_src/ -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs clang-format-14 -i
find modules/ mvsim_node_src/ mvsim_tutorial/cpp/ mvsim-cli/ tests/ -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs clang-format-14 -i
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, T*)
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
#endif

void bind_mvsim_Comms_Client(
std::function<pybind11::module&(std::string const& namespace_)>& M)
void bind_mvsim_Comms_Client(std::function<pybind11::module&(std::string const& namespace_)>& M)
{
{ // mvsim::Client file:mvsim/Comms/Client.h line:48
pybind11::class_<mvsim::Client, std::shared_ptr<mvsim::Client>> cl(
Expand All @@ -39,59 +38,52 @@ void bind_mvsim_Comms_Client(
cl.def(pybind11::init<const std::string&>(), pybind11::arg("nodeName"));

cl.def(
"setName",
(void (mvsim::Client::*)(const std::string&)) &
mvsim::Client::setName,
"setName", (void(mvsim::Client::*)(const std::string&)) & mvsim::Client::setName,
"@{ \n\nC++: mvsim::Client::setName(const std::string &) --> void",
pybind11::arg("nodeName"));
cl.def(
"serverHostAddress",
(const std::string& (mvsim::Client::*)() const) &
mvsim::Client::serverHostAddress,
(const std::string& (mvsim::Client::*)() const) & mvsim::Client::serverHostAddress,
"C++: mvsim::Client::serverHostAddress() const --> const "
"std::string &",
pybind11::return_value_policy::automatic);
cl.def(
"serverHostAddress",
(void (mvsim::Client::*)(const std::string&)) &
mvsim::Client::serverHostAddress,
(void(mvsim::Client::*)(const std::string&)) & mvsim::Client::serverHostAddress,
"C++: mvsim::Client::serverHostAddress(const std::string &) --> "
"void",
pybind11::arg("serverIpOrAddressName"));
cl.def(
"connect", (void (mvsim::Client::*)()) & mvsim::Client::connect,
"connect", (void(mvsim::Client::*)()) & mvsim::Client::connect,
"Connects to the server in a parallel thread.\n Default server "
"address is `localhost`, can be changed with\n "
"serverHostAddress().\n\nC++: mvsim::Client::connect() --> void");
cl.def(
"connected",
(bool (mvsim::Client::*)() const) & mvsim::Client::connected,
"connected", (bool(mvsim::Client::*)() const) & mvsim::Client::connected,
"Whether the client is correctly connected to the server. \n\nC++: "
"mvsim::Client::connected() const --> bool");
cl.def(
"shutdown", (void (mvsim::Client::*)()) & mvsim::Client::shutdown,
"shutdown", (void(mvsim::Client::*)()) & mvsim::Client::shutdown,
"Shutdowns the communication thread. Blocks until the thread is "
"stopped.\n There is no need to manually call this method, it is "
"called upon\n destruction. \n\nC++: mvsim::Client::shutdown() --> "
"void");
cl.def(
"callService",
(std::string(mvsim::Client::*)(
const std::string&, const std::string&)) &
(std::string(mvsim::Client::*)(const std::string&, const std::string&)) &
mvsim::Client::callService,
"Overload for python wrapper\n\nC++: "
"mvsim::Client::callService(const std::string &, const std::string "
"&) --> std::string",
pybind11::arg("serviceName"), pybind11::arg("inputSerializedMsg"));
cl.def(
"subscribeTopic",
(void (mvsim::Client::*)(
(void(mvsim::Client::*)(
const std::string&,
const class std::function<void(
const std::string&,
const class std::vector<
unsigned char,
class std::allocator<unsigned char>>&)>&)) &
unsigned char, class std::allocator<unsigned char>>&)>&)) &
mvsim::Client::subscribeTopic,
"Overload for python wrapper (callback accepts "
"bytes-string)\n\nC++: mvsim::Client::subscribeTopic(const "
Expand All @@ -100,28 +92,22 @@ void bind_mvsim_Comms_Client(
"std::allocator<unsigned char> > &)> &) --> void",
pybind11::arg("topicName"), pybind11::arg("callback"));
cl.def(
"enable_profiler",
(void (mvsim::Client::*)(bool)) & mvsim::Client::enable_profiler,
"C++: mvsim::Client::enable_profiler(bool) --> void",
pybind11::arg("enable"));
"enable_profiler", (void(mvsim::Client::*)(bool)) & mvsim::Client::enable_profiler,
"C++: mvsim::Client::enable_profiler(bool) --> void", pybind11::arg("enable"));

{ // mvsim::Client::InfoPerNode file:mvsim/Comms/Client.h line:113
auto& enclosing_class = cl;
pybind11::class_<
mvsim::Client::InfoPerNode,
std::shared_ptr<mvsim::Client::InfoPerNode>>
mvsim::Client::InfoPerNode, std::shared_ptr<mvsim::Client::InfoPerNode>>
cl(enclosing_class, "InfoPerNode", "");
cl.def(pybind11::init(
[]() { return new mvsim::Client::InfoPerNode(); }));
cl.def(pybind11::init([](mvsim::Client::InfoPerNode const& o) {
return new mvsim::Client::InfoPerNode(o);
}));
cl.def(pybind11::init([]() { return new mvsim::Client::InfoPerNode(); }));
cl.def(pybind11::init([](mvsim::Client::InfoPerNode const& o)
{ return new mvsim::Client::InfoPerNode(o); }));
cl.def_readwrite("name", &mvsim::Client::InfoPerNode::name);
cl.def(
"assign",
(struct mvsim::Client::InfoPerNode &
(mvsim::Client::InfoPerNode::*)(const struct mvsim::Client::
InfoPerNode&)) &
(mvsim::Client::InfoPerNode::*)(const struct mvsim::Client::InfoPerNode&)) &
mvsim::Client::InfoPerNode::operator=,
"C++: mvsim::Client::InfoPerNode::operator=(const struct "
"mvsim::Client::InfoPerNode &) --> struct "
Expand All @@ -132,25 +118,19 @@ void bind_mvsim_Comms_Client(
{ // mvsim::Client::InfoPerTopic file:mvsim/Comms/Client.h line:119
auto& enclosing_class = cl;
pybind11::class_<
mvsim::Client::InfoPerTopic,
std::shared_ptr<mvsim::Client::InfoPerTopic>>
mvsim::Client::InfoPerTopic, std::shared_ptr<mvsim::Client::InfoPerTopic>>
cl(enclosing_class, "InfoPerTopic", "");
cl.def(pybind11::init(
[]() { return new mvsim::Client::InfoPerTopic(); }));
cl.def(pybind11::init([](mvsim::Client::InfoPerTopic const& o) {
return new mvsim::Client::InfoPerTopic(o);
}));
cl.def(pybind11::init([]() { return new mvsim::Client::InfoPerTopic(); }));
cl.def(pybind11::init([](mvsim::Client::InfoPerTopic const& o)
{ return new mvsim::Client::InfoPerTopic(o); }));
cl.def_readwrite("name", &mvsim::Client::InfoPerTopic::name);
cl.def_readwrite("type", &mvsim::Client::InfoPerTopic::type);
cl.def_readwrite(
"endpoints", &mvsim::Client::InfoPerTopic::endpoints);
cl.def_readwrite(
"publishers", &mvsim::Client::InfoPerTopic::publishers);
cl.def_readwrite("endpoints", &mvsim::Client::InfoPerTopic::endpoints);
cl.def_readwrite("publishers", &mvsim::Client::InfoPerTopic::publishers);
cl.def(
"assign",
(struct mvsim::Client::InfoPerTopic &
(mvsim::Client::InfoPerTopic::*)(const struct mvsim::Client::
InfoPerTopic&)) &
(mvsim::Client::InfoPerTopic::*)(const struct mvsim::Client::InfoPerTopic&)) &
mvsim::Client::InfoPerTopic::operator=,
"C++: mvsim::Client::InfoPerTopic::operator=(const struct "
"mvsim::Client::InfoPerTopic &) --> struct "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,27 @@ PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
#endif

// mvsim::UnexpectedMessageException file:mvsim/Comms/common.h line:49
struct PyCallBack_mvsim_UnexpectedMessageException
: public mvsim::UnexpectedMessageException
struct PyCallBack_mvsim_UnexpectedMessageException : public mvsim::UnexpectedMessageException
{
using mvsim::UnexpectedMessageException::UnexpectedMessageException;

const char* what() const throw() override
{
pybind11::gil_scoped_acquire gil;
pybind11::function overload = pybind11::get_overload(
static_cast<const mvsim::UnexpectedMessageException*>(this),
"what");
static_cast<const mvsim::UnexpectedMessageException*>(this), "what");
if (overload)
{
auto o =
overload.operator()<pybind11::return_value_policy::reference>();
if (pybind11::detail::cast_is_temporary_value_reference<
const char*>::value)
auto o = overload.operator()<pybind11::return_value_policy::reference>();
if (pybind11::detail::cast_is_temporary_value_reference<const char*>::value)
{
// pybind11 <=2.4: overload_caster_t, otherwise: override_caster_t
#if (PYBIND11_MAJOR_VERSION == 2 && PYBIND11_MINOR_VERSION <= 4)
static pybind11::detail::overload_caster_t<const char*> caster;
#else
static pybind11::detail::override_caster_t<const char*> caster;
#endif
return pybind11::detail::cast_ref<const char*>(
std::move(o), caster);
return pybind11::detail::cast_ref<const char*>(std::move(o), caster);
}
else
return pybind11::detail::cast_safe<const char*>(std::move(o));
Expand All @@ -49,30 +44,24 @@ struct PyCallBack_mvsim_UnexpectedMessageException
}
};

void bind_mvsim_Comms_common(
std::function<pybind11::module&(std::string const& namespace_)>& M)
void bind_mvsim_Comms_common(std::function<pybind11::module&(std::string const& namespace_)>& M)
{
{ // mvsim::UnexpectedMessageException file:mvsim/Comms/common.h line:49
pybind11::class_<
mvsim::UnexpectedMessageException,
std::shared_ptr<mvsim::UnexpectedMessageException>,
mvsim::UnexpectedMessageException, std::shared_ptr<mvsim::UnexpectedMessageException>,
PyCallBack_mvsim_UnexpectedMessageException, std::runtime_error>
cl(M("mvsim"), "UnexpectedMessageException", "");
cl.def(pybind11::init<const char*>(), pybind11::arg("reason"));

cl.def(pybind11::init(
[](PyCallBack_mvsim_UnexpectedMessageException const& o) {
return new PyCallBack_mvsim_UnexpectedMessageException(o);
}));
cl.def(pybind11::init([](mvsim::UnexpectedMessageException const& o) {
return new mvsim::UnexpectedMessageException(o);
}));
cl.def(pybind11::init([](PyCallBack_mvsim_UnexpectedMessageException const& o)
{ return new PyCallBack_mvsim_UnexpectedMessageException(o); }));
cl.def(pybind11::init([](mvsim::UnexpectedMessageException const& o)
{ return new mvsim::UnexpectedMessageException(o); }));
cl.def(
"assign",
(class mvsim::UnexpectedMessageException &
(mvsim::
UnexpectedMessageException::*)(const class mvsim::
UnexpectedMessageException&)) &
(mvsim::UnexpectedMessageException::*)(const class mvsim::
UnexpectedMessageException&)) &
mvsim::UnexpectedMessageException::operator=,
"C++: mvsim::UnexpectedMessageException::operator=(const class "
"mvsim::UnexpectedMessageException &) --> class "
Expand Down
39 changes: 18 additions & 21 deletions modules/comms/python/generated-sources-pybind/pymvsim_comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@

typedef std::function<pybind11::module&(std::string const&)> ModuleGetter;

void bind_std_exception(
std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_std_stdexcept(
std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_mvsim_Comms_common(
std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_mvsim_Comms_Client(
std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_std_exception(std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_std_stdexcept(std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_mvsim_Comms_common(std::function<pybind11::module&(std::string const& namespace_)>& M);
void bind_mvsim_Comms_Client(std::function<pybind11::module&(std::string const& namespace_)>& M);

PYBIND11_MODULE(pymvsim_comms, root_module)
{
root_module.doc() = "pymvsim_comms module";

std::map<std::string, pybind11::module> modules;
ModuleGetter M = [&](std::string const& namespace_) -> pybind11::module& {
ModuleGetter M = [&](std::string const& namespace_) -> pybind11::module&
{
auto it = modules.find(namespace_);
if (it == modules.end())
throw std::runtime_error(
"Attempt to access pybind11::module for namespace " +
namespace_ + " before it was created!!!");
"Attempt to access pybind11::module for namespace " + namespace_ +
" before it was created!!!");
return it->second;
};

Expand All @@ -39,14 +36,15 @@ PYBIND11_MODULE(pymvsim_comms, root_module)
"global",
};

auto mangle_namespace_name([](std::string const& ns) -> std::string {
if (std::find(
reserved_python_words.begin(), reserved_python_words.end(),
ns) == reserved_python_words.end())
return ns;
else
return ns + '_';
});
auto mangle_namespace_name(
[](std::string const& ns) -> std::string
{
if (std::find(reserved_python_words.begin(), reserved_python_words.end(), ns) ==
reserved_python_words.end())
return ns;
else
return ns + '_';
});

std::vector<std::pair<std::string, std::string>> sub_modules{
{"", "mvsim"},
Expand All @@ -56,8 +54,7 @@ PYBIND11_MODULE(pymvsim_comms, root_module)
modules[p.first.size() ? p.first + "::" + p.second : p.second] =
modules[p.first].def_submodule(
mangle_namespace_name(p.second).c_str(),
("Bindings for " + p.first + "::" + p.second + " namespace")
.c_str());
("Bindings for " + p.first + "::" + p.second + " namespace").c_str());

// pybind11::class_<std::shared_ptr<void>>(M(""), "_encapsulated_data_");

Expand Down
34 changes: 12 additions & 22 deletions modules/comms/python/generated-sources-pybind/std/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@ struct PyCallBack_std_exception : public std::exception
const char* what() const throw() override
{
pybind11::gil_scoped_acquire gil;
pybind11::function overload = pybind11::get_overload(
static_cast<const std::exception*>(this), "what");
pybind11::function overload =
pybind11::get_overload(static_cast<const std::exception*>(this), "what");
if (overload)
{
auto o =
overload.operator()<pybind11::return_value_policy::reference>();
if (pybind11::detail::cast_is_temporary_value_reference<
const char*>::value)
auto o = overload.operator()<pybind11::return_value_policy::reference>();
if (pybind11::detail::cast_is_temporary_value_reference<const char*>::value)
{
// pybind11 <=2.4: overload_caster_t, otherwise: override_caster_t
#if (PYBIND11_MAJOR_VERSION == 2 && PYBIND11_MINOR_VERSION <= 4)
static pybind11::detail::overload_caster_t<const char*> caster;
#else
static pybind11::detail::override_caster_t<const char*> caster;
#endif
return pybind11::detail::cast_ref<const char*>(
std::move(o), caster);
return pybind11::detail::cast_ref<const char*>(std::move(o), caster);
}
else
return pybind11::detail::cast_safe<const char*>(std::move(o));
Expand All @@ -46,33 +43,26 @@ struct PyCallBack_std_exception : public std::exception
}
};

void bind_std_exception(
std::function<pybind11::module&(std::string const& namespace_)>& M)
void bind_std_exception(std::function<pybind11::module&(std::string const& namespace_)>& M)
{
{ // std::exception file:bits/exception.h line:61
pybind11::class_<
std::exception, std::shared_ptr<std::exception>,
PyCallBack_std_exception>
pybind11::class_<std::exception, std::shared_ptr<std::exception>, PyCallBack_std_exception>
cl(M("std"), "exception", "");
cl.def(pybind11::init(
[]() { return new std::exception(); },
[]() { return new PyCallBack_std_exception(); }));
cl.def(pybind11::init([](PyCallBack_std_exception const& o) {
return new PyCallBack_std_exception(o);
}));
cl.def(pybind11::init(
[](std::exception const& o) { return new std::exception(o); }));
cl.def(pybind11::init([](PyCallBack_std_exception const& o)
{ return new PyCallBack_std_exception(o); }));
cl.def(pybind11::init([](std::exception const& o) { return new std::exception(o); }));
cl.def(
"assign",
(class std::exception &
(std::exception::*)(const class std::exception&)) &
(class std::exception & (std::exception::*)(const class std::exception&)) &
std::exception::operator=,
"C++: std::exception::operator=(const class std::exception &) --> "
"class std::exception &",
pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def(
"what",
(const char* (std::exception::*)() const) & std::exception::what,
"what", (const char* (std::exception::*)() const) & std::exception::what,
"C++: std::exception::what() const --> const char *",
pybind11::return_value_policy::automatic);
}
Expand Down
Loading