Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Call super() constructors when subclassing
Browse files Browse the repository at this point in the history
- The super() will zero-initialize the properties
- Remove extra constructor stuff, it's not actually needed
- Actually fixes #2
  • Loading branch information
virtuald committed Mar 12, 2018
1 parent 6f2032f commit 80d053b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 4 additions & 20 deletions pathfinder/_pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,15 @@ PYBIND11_MODULE(_pathfinder, m) {

// followers/distance.h
py::class_<FollowerConfig>(m, "FollowerConfig")
.def(py::init<>([](){
return std::unique_ptr<FollowerConfig>(new FollowerConfig{
0.0, 0.0, 0.0, 0.0, 0.0
});
}))
.def(py::init<>())
.def_readwrite("kp", &FollowerConfig::kp)
.def_readwrite("ki", &FollowerConfig::ki)
.def_readwrite("kd", &FollowerConfig::kd)
.def_readwrite("kv", &FollowerConfig::kv)
.def_readwrite("ka", &FollowerConfig::ka);

py::class_<DistanceFollower>(m, "DistanceFollower")
.def(py::init<>([](){
return std::unique_ptr<DistanceFollower>(new DistanceFollower{
0.0, 0.0, 0.0, 0, 0
});
}))
.def(py::init<>())
.def_readwrite("last_error", &DistanceFollower::last_error)
.def_readwrite("heading", &DistanceFollower::heading)
.def_readwrite("output", &DistanceFollower::output)
Expand All @@ -250,11 +242,7 @@ PYBIND11_MODULE(_pathfinder, m) {

// followers/encoder.h
py::class_<EncoderConfig>(m, "EncoderConfig")
.def(py::init<>([](){
return std::unique_ptr<EncoderConfig>(new EncoderConfig{
0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
});
}))
.def(py::init<>())
.def_readwrite("initial_position", &EncoderConfig::initial_position)
.def_readwrite("ticks_per_revolution", &EncoderConfig::ticks_per_revolution)
.def_readwrite("wheel_circumference", &EncoderConfig::wheel_circumference)
Expand All @@ -265,11 +253,7 @@ PYBIND11_MODULE(_pathfinder, m) {
.def_readwrite("ka", &EncoderConfig::ka);

py::class_<EncoderFollower>(m, "EncoderFollower")
.def(py::init<>([](){
return std::unique_ptr<EncoderFollower>(new EncoderFollower{
0.0, 0.0, 0.0, 0, 0
});
}))
.def(py::init<>())
.def_readwrite("last_error", &EncoderFollower::last_error)
.def_readwrite("heading", &EncoderFollower::heading)
.def_readwrite("output", &EncoderFollower::output)
Expand Down
2 changes: 2 additions & 0 deletions pathfinder/followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DistanceFollower(_DistanceFollower):
"""

def __init__(self, trajectory: typing.List[Segment]):
super().__init__()
self.trajectory = trajectory
self.cfg = FollowerConfig()

Expand Down Expand Up @@ -94,6 +95,7 @@ class EncoderFollower(_EncoderFollower):
"""

def __init__(self, trajectory: typing.List[Segment]):
super().__init__()
self.trajectory = trajectory
self.cfg = EncoderConfig()

Expand Down

0 comments on commit 80d053b

Please sign in to comment.