Files
balance/dm_imu/pybind_imu.cpp
ydy0615 ced3669fac refactor(package): rename to dm_imu and restructure directories
Renamed package from dm_imu_pkg to dm_imu across PKG-INFO, egg-info files,
and directories. Updated CMakeLists.txt, __init__.py, and top_level.txt to
reflect new structure. Bumped gradio version from <5.0 to <6.0 in
dependencies. This refactoring improves naming consistency and streamlines
the package layout for better maintainability.
2025-12-10 19:32:28 +08:00

37 lines
989 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "imu_driver.h"
namespace py = pybind11;
using namespace dmbot_serial;
/* Convert IMU_Data to a Python dict */
py::dict imu_data_to_dict(const IMU_Data &data) {
py::dict d;
d["accx"] = data.accx;
d["accy"] = data.accy;
d["accz"] = data.accz;
d["gyrox"] = data.gyrox;
d["gyroy"] = data.gyroy;
d["gyroz"] = data.gyroz;
d["roll"] = data.roll;
d["pitch"] = data.pitch;
d["yaw"] = data.yaw;
return d;
}
PYBIND11_MODULE(imu_py, m) {
m.doc() = "Python bindings for DMIMU driver";
py::class_<DmImu>(m, "DmImu")
.def(py::init<const std::string&, int>(),
py::arg("port") = "/dev/ttyACM1",
py::arg("baud") = 921600)
.def("start", &DmImu::start)
.def("stop", &DmImu::stop)
.def("getData",
[](const DmImu &self) {
return imu_data_to_dict(self.getData());
});
}