feat: add IMU Python package with pybind11 bindings
- Add dm_imu_pkg/__init__.py to dynamically load compiled IMU module during development and installation - Update .vscode/settings.json to ignore missing CMakeLists for flexible builds - Generate egg-info metadata and package structure for distribution
This commit is contained in:
36
src/pybind_imu/pybind_imu.cpp
Normal file
36
src/pybind_imu/pybind_imu.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
#include "dm_imu/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 DM‑IMU 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());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user