Skip to content

Commit 70c5270

Browse files
committed
Add: Use offsets in ServoArray
1 parent ba2605e commit 70c5270

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/lib/servoarray.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ namespace ServoArray {
2222

2323
ServoArray::ServoArray(std::shared_ptr<Driver> driver, const std::vector<double>& offsets) : driver_(driver), offsets_(offsets) {
2424
this->cache_.resize(this->size());
25+
this->offsets_.resize(this->size());
2526
}
2627

2728
ServoArray::ServoArray(const std::string& name, const DriverParams& params, DriverManager& manager) : driver_(manager.load(name, params)) {
2829
this->cache_.resize(this->size());
30+
this->offsets_.resize(this->size());
2931
}
3032

3133
void ServoArray::write(std::size_t index, double rad) {
32-
this->driver_->write(index, rad);
33-
this->cache_[index] = rad;
34+
auto const value = this->offsets_[index] + rad;
35+
this->driver_->write(index, value);
36+
this->cache_[index] = value;
3437
}
3538

3639
double ServoArray::read(std::size_t index) {
3740
switch(this->read_mode_) {
3841
case ReadMode::Cached:
39-
return this->cache_[index];
42+
return this->cache_[index] - this->offsets_[index];
4043
case ReadMode::Direct:
41-
return this->driver_->read(index);
44+
return this->driver_->read(index) - this->offsets_[index];
4245
default:
4346
assert(false); // unreachable
4447
}

0 commit comments

Comments
 (0)