kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Renamed C++ Servo functions to match MP
rodzic
c5be5be759
commit
1efa75a590
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
namespace servo {
|
namespace servo {
|
||||||
Servo::Servo(uint pin, CalibrationType type, float freq)
|
Servo::Servo(uint pin, CalibrationType type, float freq)
|
||||||
: pin(pin), state(type), pwm_frequency(freq) {
|
: servo_pin(pin), state(type), pwm_frequency(freq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Servo::Servo(uint pin, const Calibration& calibration, float freq)
|
Servo::Servo(uint pin, const Calibration& calibration, float freq)
|
||||||
: pin(pin), state(calibration), pwm_frequency(freq) {
|
: servo_pin(pin), state(calibration), pwm_frequency(freq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Servo::~Servo() {
|
Servo::~Servo() {
|
||||||
gpio_set_function(pin, GPIO_FUNC_NULL);
|
gpio_set_function(servo_pin, GPIO_FUNC_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Servo::init() {
|
bool Servo::init() {
|
||||||
|
@ -30,18 +30,18 @@ namespace servo {
|
||||||
// Apply the divider
|
// Apply the divider
|
||||||
pwm_config_set_clkdiv(&pwm_cfg, (float)div16 / 16.0f); // There's no 'pwm_config_set_clkdiv_int_frac' for some reason...
|
pwm_config_set_clkdiv(&pwm_cfg, (float)div16 / 16.0f); // There's no 'pwm_config_set_clkdiv_int_frac' for some reason...
|
||||||
|
|
||||||
pwm_init(pwm_gpio_to_slice_num(pin), &pwm_cfg, true);
|
pwm_init(pwm_gpio_to_slice_num(servo_pin), &pwm_cfg, true);
|
||||||
gpio_set_function(pin, GPIO_FUNC_PWM);
|
gpio_set_function(servo_pin, GPIO_FUNC_PWM);
|
||||||
|
|
||||||
pwm_set_gpio_level(pin, 0);
|
pwm_set_gpio_level(servo_pin, 0);
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint Servo::get_pin() const {
|
uint Servo::pin() const {
|
||||||
return pin;
|
return servo_pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::enable() {
|
void Servo::enable() {
|
||||||
|
@ -56,27 +56,27 @@ namespace servo {
|
||||||
return state.is_enabled();
|
return state.is_enabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_pulse() const {
|
float Servo::pulse() const {
|
||||||
return state.get_pulse();
|
return state.get_pulse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::set_pulse(float pulse) {
|
void Servo::pulse(float pulse) {
|
||||||
apply_pulse(state.set_pulse(pulse));
|
apply_pulse(state.set_pulse_with_return(pulse));
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_value() const {
|
float Servo::value() const {
|
||||||
return state.get_value();
|
return state.get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::set_value(float value) {
|
void Servo::value(float value) {
|
||||||
apply_pulse(state.set_value(value));
|
apply_pulse(state.set_value_with_return(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_frequency() const {
|
float Servo::frequency() const {
|
||||||
return pwm_frequency;
|
return pwm_frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Servo::set_frequency(float freq) {
|
bool Servo::frequency(float freq) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if((freq >= ServoState::MIN_FREQUENCY) && (freq <= ServoState::MAX_FREQUENCY)) {
|
if((freq >= ServoState::MIN_FREQUENCY) && (freq <= ServoState::MAX_FREQUENCY)) {
|
||||||
|
@ -92,7 +92,7 @@ namespace servo {
|
||||||
pwm_period = period;
|
pwm_period = period;
|
||||||
pwm_frequency = freq;
|
pwm_frequency = freq;
|
||||||
|
|
||||||
uint pin_num = pwm_gpio_to_slice_num(pin);
|
uint pin_num = pwm_gpio_to_slice_num(servo_pin);
|
||||||
|
|
||||||
// Apply the new divider
|
// Apply the new divider
|
||||||
uint8_t div = div16 >> 4;
|
uint8_t div = div16 >> 4;
|
||||||
|
@ -118,36 +118,36 @@ namespace servo {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_min_value() const {
|
float Servo::min_value() const {
|
||||||
return state.get_min_value();
|
return state.get_min_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_mid_value() const {
|
float Servo::mid_value() const {
|
||||||
return state.get_mid_value();
|
return state.get_mid_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Servo::get_max_value() const {
|
float Servo::max_value() const {
|
||||||
return state.get_max_value();
|
return state.get_max_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::to_min() {
|
void Servo::to_min() {
|
||||||
apply_pulse(state.to_min());
|
apply_pulse(state.to_min_with_return());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::to_mid() {
|
void Servo::to_mid() {
|
||||||
apply_pulse(state.to_mid());
|
apply_pulse(state.to_mid_with_return());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::to_max() {
|
void Servo::to_max() {
|
||||||
apply_pulse(state.to_max());
|
apply_pulse(state.to_max_with_return());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::to_percent(float in, float in_min, float in_max) {
|
void Servo::to_percent(float in, float in_min, float in_max) {
|
||||||
apply_pulse(state.to_percent(in, in_min, in_max));
|
apply_pulse(state.to_percent_with_return(in, in_min, in_max));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::to_percent(float in, float in_min, float in_max, float value_min, float value_max) {
|
void Servo::to_percent(float in, float in_min, float in_max, float value_min, float value_max) {
|
||||||
apply_pulse(state.to_percent(in, in_min, in_max, value_min, value_max));
|
apply_pulse(state.to_percent_with_return(in, in_min, in_max, value_min, value_max));
|
||||||
}
|
}
|
||||||
|
|
||||||
Calibration& Servo::calibration() {
|
Calibration& Servo::calibration() {
|
||||||
|
@ -159,6 +159,6 @@ namespace servo {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Servo::apply_pulse(float pulse) {
|
void Servo::apply_pulse(float pulse) {
|
||||||
pwm_set_gpio_level(pin, (uint16_t)ServoState::pulse_to_level(pulse, pwm_period, pwm_frequency));
|
pwm_set_gpio_level(servo_pin, (uint16_t)ServoState::pulse_to_level(pulse, pwm_period, pwm_frequency));
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -11,7 +11,7 @@ namespace servo {
|
||||||
// Variables
|
// Variables
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private:
|
private:
|
||||||
uint pin;
|
uint servo_pin;
|
||||||
ServoState state;
|
ServoState state;
|
||||||
pwm_config pwm_cfg;
|
pwm_config pwm_cfg;
|
||||||
uint16_t pwm_period;
|
uint16_t pwm_period;
|
||||||
|
@ -33,25 +33,25 @@ namespace servo {
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
// For print access in micropython
|
// For print access in micropython
|
||||||
uint get_pin() const;
|
uint pin() const;
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
bool is_enabled() const;
|
bool is_enabled() const;
|
||||||
|
|
||||||
float get_pulse() const;
|
float pulse() const;
|
||||||
void set_pulse(float pulse);
|
void pulse(float pulse);
|
||||||
|
|
||||||
float get_value() const;
|
float value() const;
|
||||||
void set_value(float value);
|
void value(float value);
|
||||||
|
|
||||||
float get_frequency() const;
|
float frequency() const;
|
||||||
bool set_frequency(float freq);
|
bool frequency(float freq);
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
float get_min_value() const;
|
float min_value() const;
|
||||||
float get_mid_value() const;
|
float mid_value() const;
|
||||||
float get_max_value() const;
|
float max_value() const;
|
||||||
|
|
||||||
void to_min();
|
void to_min();
|
||||||
void to_mid();
|
void to_mid();
|
||||||
|
|
|
@ -80,11 +80,11 @@ namespace servo {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ServoCluster::get_count() const {
|
uint8_t ServoCluster::count() const {
|
||||||
return pwms.get_chan_count();
|
return pwms.get_chan_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ServoCluster::get_pin(uint8_t servo) const {
|
uint8_t ServoCluster::pin(uint8_t servo) const {
|
||||||
return pwms.get_chan_pin(servo);
|
return pwms.get_chan_pin(servo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,122 +157,122 @@ namespace servo {
|
||||||
return states[servo].is_enabled();
|
return states[servo].is_enabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_pulse(uint servo) const {
|
float ServoCluster::pulse(uint servo) const {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
return states[servo].get_pulse();
|
return states[servo].get_pulse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_pulse(uint servo, float pulse, bool load) {
|
void ServoCluster::pulse(uint servo, float pulse, bool load) {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
float new_pulse = states[servo].set_pulse(pulse);
|
float new_pulse = states[servo].set_pulse_with_return(pulse);
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_pulse(const uint8_t *servos, uint8_t length, float pulse, bool load) {
|
void ServoCluster::pulse(const uint8_t *servos, uint8_t length, float pulse, bool load) {
|
||||||
assert(servos != nullptr);
|
assert(servos != nullptr);
|
||||||
for(uint8_t i = 0; i < length; i++) {
|
for(uint8_t i = 0; i < length; i++) {
|
||||||
set_pulse(servos[i], pulse, false);
|
this->pulse(servos[i], pulse, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_pulse(std::initializer_list<uint8_t> servos, float pulse, bool load) {
|
void ServoCluster::pulse(std::initializer_list<uint8_t> servos, float pulse, bool load) {
|
||||||
for(auto servo : servos) {
|
for(auto servo : servos) {
|
||||||
set_pulse(servo, pulse, false);
|
this->pulse(servo, pulse, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_all_pulses(float pulse, bool load) {
|
void ServoCluster::all_to_pulse(float pulse, bool load) {
|
||||||
uint8_t servo_count = pwms.get_chan_count();
|
uint8_t servo_count = pwms.get_chan_count();
|
||||||
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
||||||
set_pulse(servo, pulse, false);
|
this->pulse(servo, pulse, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_value(uint servo) const {
|
float ServoCluster::value(uint servo) const {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
return states[servo].get_value();
|
return states[servo].get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_value(uint servo, float value, bool load) {
|
void ServoCluster::value(uint servo, float value, bool load) {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
float new_pulse = states[servo].set_value(value);
|
float new_pulse = states[servo].set_value_with_return(value);
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_value(const uint8_t *servos, uint8_t length, float value, bool load) {
|
void ServoCluster::value(const uint8_t *servos, uint8_t length, float value, bool load) {
|
||||||
assert(servos != nullptr);
|
assert(servos != nullptr);
|
||||||
for(uint8_t i = 0; i < length; i++) {
|
for(uint8_t i = 0; i < length; i++) {
|
||||||
set_value(servos[i], value, false);
|
this->value(servos[i], value, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_value(std::initializer_list<uint8_t> servos, float value, bool load) {
|
void ServoCluster::value(std::initializer_list<uint8_t> servos, float value, bool load) {
|
||||||
for(auto servo : servos) {
|
for(auto servo : servos) {
|
||||||
set_value(servo, value, false);
|
this->value(servo, value, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_all_values(float value, bool load) {
|
void ServoCluster::all_to_value(float value, bool load) {
|
||||||
uint8_t servo_count = pwms.get_chan_count();
|
uint8_t servo_count = pwms.get_chan_count();
|
||||||
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
||||||
set_value(servo, value, false);
|
this->value(servo, value, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_phase(uint servo) const {
|
float ServoCluster::phase(uint servo) const {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
return servo_phases[servo];
|
return servo_phases[servo];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_phase(uint servo, float phase, bool load) {
|
void ServoCluster::phase(uint servo, float phase, bool load) {
|
||||||
assert(servo < pwms.get_chan_count());
|
assert(servo < pwms.get_chan_count());
|
||||||
servo_phases[servo] = MIN(MAX(phase, 0.0f), 1.0f);
|
servo_phases[servo] = MIN(MAX(phase, 0.0f), 1.0f);
|
||||||
pwms.set_chan_offset(servo, (uint32_t)(servo_phases[servo] * (float)pwms.get_wrap()), load);
|
pwms.set_chan_offset(servo, (uint32_t)(servo_phases[servo] * (float)pwms.get_wrap()), load);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_phase(const uint8_t *servos, uint8_t length, float phase, bool load) {
|
void ServoCluster::phase(const uint8_t *servos, uint8_t length, float phase, bool load) {
|
||||||
assert(servos != nullptr);
|
assert(servos != nullptr);
|
||||||
for(uint8_t i = 0; i < length; i++) {
|
for(uint8_t i = 0; i < length; i++) {
|
||||||
set_phase(servos[i], phase, false);
|
this->phase(servos[i], phase, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_phase(std::initializer_list<uint8_t> servos, float phase, bool load) {
|
void ServoCluster::phase(std::initializer_list<uint8_t> servos, float phase, bool load) {
|
||||||
for(auto servo : servos) {
|
for(auto servo : servos) {
|
||||||
set_phase(servo, phase, false);
|
this->phase(servo, phase, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::set_all_phases(float phase, bool load) {
|
void ServoCluster::all_to_phase(float phase, bool load) {
|
||||||
uint8_t servo_count = pwms.get_chan_count();
|
uint8_t servo_count = pwms.get_chan_count();
|
||||||
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
||||||
set_phase(servo, phase, false);
|
this->phase(servo, phase, false);
|
||||||
}
|
}
|
||||||
if(load)
|
if(load)
|
||||||
pwms.load_pwm();
|
pwms.load_pwm();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_frequency() const {
|
float ServoCluster::frequency() const {
|
||||||
return pwm_frequency;
|
return pwm_frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServoCluster::set_frequency(float freq) {
|
bool ServoCluster::frequency(float freq) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
if((freq >= ServoState::MIN_FREQUENCY) && (freq <= ServoState::MAX_FREQUENCY)) {
|
if((freq >= ServoState::MIN_FREQUENCY) && (freq <= ServoState::MAX_FREQUENCY)) {
|
||||||
|
@ -306,24 +306,24 @@ namespace servo {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_min_value(uint servo) const {
|
float ServoCluster::min_value(uint servo) const {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
return states[servo].get_min_value();
|
return states[servo].get_min_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_mid_value(uint servo) const {
|
float ServoCluster::mid_value(uint servo) const {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
return states[servo].get_mid_value();
|
return states[servo].get_mid_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoCluster::get_max_value(uint servo) const {
|
float ServoCluster::max_value(uint servo) const {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
return states[servo].get_max_value();
|
return states[servo].get_max_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoCluster::to_min(uint servo, bool load) {
|
void ServoCluster::to_min(uint servo, bool load) {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
float new_pulse = states[servo].to_min();
|
float new_pulse = states[servo].to_min_with_return();
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ namespace servo {
|
||||||
|
|
||||||
void ServoCluster::to_mid(uint servo, bool load) {
|
void ServoCluster::to_mid(uint servo, bool load) {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
float new_pulse = states[servo].to_mid();
|
float new_pulse = states[servo].to_mid_with_return();
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ namespace servo {
|
||||||
|
|
||||||
void ServoCluster::to_max(uint servo, bool load) {
|
void ServoCluster::to_max(uint servo, bool load) {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
float new_pulse = states[servo].to_max();
|
float new_pulse = states[servo].to_max_with_return();
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ namespace servo {
|
||||||
|
|
||||||
void ServoCluster::to_percent(uint servo, float in, float in_min, float in_max, bool load) {
|
void ServoCluster::to_percent(uint servo, float in, float in_min, float in_max, bool load) {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
float new_pulse = states[servo].to_percent(in, in_min, in_max);
|
float new_pulse = states[servo].to_percent_with_return(in, in_min, in_max);
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +451,7 @@ namespace servo {
|
||||||
|
|
||||||
void ServoCluster::to_percent(uint servo, float in, float in_min, float in_max, float value_min, float value_max, bool load) {
|
void ServoCluster::to_percent(uint servo, float in, float in_min, float in_max, float value_min, float value_max, bool load) {
|
||||||
assert(is_assigned(servo));
|
assert(is_assigned(servo));
|
||||||
float new_pulse = states[servo].to_percent(in, in_min, in_max, value_min, value_max);
|
float new_pulse = states[servo].to_percent_with_return(in, in_min, in_max, value_min, value_max);
|
||||||
apply_pulse(servo, new_pulse, load);
|
apply_pulse(servo, new_pulse, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ namespace servo {
|
||||||
public:
|
public:
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
uint8_t get_count() const;
|
uint8_t count() const;
|
||||||
uint8_t get_pin(uint8_t servo) const;
|
uint8_t pin(uint8_t servo) const;
|
||||||
|
|
||||||
void enable(uint servo, bool load = true);
|
void enable(uint servo, bool load = true);
|
||||||
void enable(const uint8_t *servos, uint8_t length, bool load = true);
|
void enable(const uint8_t *servos, uint8_t length, bool load = true);
|
||||||
|
@ -57,31 +57,31 @@ namespace servo {
|
||||||
|
|
||||||
bool is_enabled(uint servo) const;
|
bool is_enabled(uint servo) const;
|
||||||
|
|
||||||
float get_pulse(uint servo) const;
|
float pulse(uint servo) const;
|
||||||
void set_pulse(uint servo, float pulse, bool load = true);
|
void pulse(uint servo, float pulse, bool load = true);
|
||||||
void set_pulse(const uint8_t *servos, uint8_t length, float pulse, bool load = true);
|
void pulse(const uint8_t *servos, uint8_t length, float pulse, bool load = true);
|
||||||
void set_pulse(std::initializer_list<uint8_t> servos, float pulse, bool load = true);
|
void pulse(std::initializer_list<uint8_t> servos, float pulse, bool load = true);
|
||||||
void set_all_pulses(float pulse, bool load = true);
|
void all_to_pulse(float pulse, bool load = true);
|
||||||
|
|
||||||
float get_value(uint servo) const;
|
float value(uint servo) const;
|
||||||
void set_value(uint servo, float value, bool load = true);
|
void value(uint servo, float value, bool load = true);
|
||||||
void set_value(const uint8_t *servos, uint8_t length, float value, bool load = true);
|
void value(const uint8_t *servos, uint8_t length, float value, bool load = true);
|
||||||
void set_value(std::initializer_list<uint8_t> servos, float value, bool load = true);
|
void value(std::initializer_list<uint8_t> servos, float value, bool load = true);
|
||||||
void set_all_values(float value, bool load = true);
|
void all_to_value(float value, bool load = true);
|
||||||
|
|
||||||
float get_phase(uint servo) const;
|
float phase(uint servo) const;
|
||||||
void set_phase(uint servo, float phase, bool load = true);
|
void phase(uint servo, float phase, bool load = true);
|
||||||
void set_phase(const uint8_t *servos, uint8_t length, float phase, bool load = true);
|
void phase(const uint8_t *servos, uint8_t length, float phase, bool load = true);
|
||||||
void set_phase(std::initializer_list<uint8_t> servos, float phase, bool load = true);
|
void phase(std::initializer_list<uint8_t> servos, float phase, bool load = true);
|
||||||
void set_all_phases(float phase, bool load = true);
|
void all_to_phase(float phase, bool load = true);
|
||||||
|
|
||||||
float get_frequency() const;
|
float frequency() const;
|
||||||
bool set_frequency(float freq);
|
bool frequency(float freq);
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
float get_min_value(uint servo) const;
|
float min_value(uint servo) const;
|
||||||
float get_mid_value(uint servo) const;
|
float mid_value(uint servo) const;
|
||||||
float get_max_value(uint servo) const;
|
float max_value(uint servo) const;
|
||||||
|
|
||||||
void to_min(uint servo, bool load = true);
|
void to_min(uint servo, bool load = true);
|
||||||
void to_min(const uint8_t *servos, uint8_t length, bool load = true);
|
void to_min(const uint8_t *servos, uint8_t length, bool load = true);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace servo {
|
||||||
// Has the servo not had a pulse value set before being enabled?
|
// Has the servo not had a pulse value set before being enabled?
|
||||||
if(last_enabled_pulse < MIN_VALID_PULSE) {
|
if(last_enabled_pulse < MIN_VALID_PULSE) {
|
||||||
// Set the servo to its middle
|
// Set the servo to its middle
|
||||||
return to_mid();
|
return to_mid_with_return();
|
||||||
}
|
}
|
||||||
return _enable();
|
return _enable();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ namespace servo {
|
||||||
return last_enabled_pulse;
|
return last_enabled_pulse;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::set_pulse(float pulse) {
|
float ServoState::set_pulse_with_return(float pulse) {
|
||||||
if(pulse >= MIN_VALID_PULSE) {
|
if(pulse >= MIN_VALID_PULSE) {
|
||||||
float value_out, pulse_out;
|
float value_out, pulse_out;
|
||||||
if(calib.pulse_to_value(pulse, value_out, pulse_out)) {
|
if(calib.pulse_to_value(pulse, value_out, pulse_out)) {
|
||||||
|
@ -55,7 +55,7 @@ namespace servo {
|
||||||
return servo_value;
|
return servo_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::set_value(float value) {
|
float ServoState::set_value_with_return(float value) {
|
||||||
float pulse_out, value_out;
|
float pulse_out, value_out;
|
||||||
if(calib.value_to_pulse(value, pulse_out, value_out)) {
|
if(calib.value_to_pulse(value, pulse_out, value_out)) {
|
||||||
last_enabled_pulse = pulse_out;
|
last_enabled_pulse = pulse_out;
|
||||||
|
@ -91,26 +91,26 @@ namespace servo {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::to_min() {
|
float ServoState::to_min_with_return() {
|
||||||
return set_value(get_min_value());
|
return set_value_with_return(get_min_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::to_mid() {
|
float ServoState::to_mid_with_return() {
|
||||||
return set_value(get_mid_value());
|
return set_value_with_return(get_mid_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::to_max() {
|
float ServoState::to_max_with_return() {
|
||||||
return set_value(get_max_value());
|
return set_value_with_return(get_max_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::to_percent(float in, float in_min, float in_max) {
|
float ServoState::to_percent_with_return(float in, float in_min, float in_max) {
|
||||||
float value = Calibration::map_float(in, in_min, in_max, get_min_value(), get_max_value());
|
float value = Calibration::map_float(in, in_min, in_max, get_min_value(), get_max_value());
|
||||||
return set_value(value);
|
return set_value_with_return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServoState::to_percent(float in, float in_min, float in_max, float value_min, float value_max) {
|
float ServoState::to_percent_with_return(float in, float in_min, float in_max, float value_min, float value_max) {
|
||||||
float value = Calibration::map_float(in, in_min, in_max, value_min, value_max);
|
float value = Calibration::map_float(in, in_min, in_max, value_min, value_max);
|
||||||
return set_value(value);
|
return set_value_with_return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Calibration& ServoState::calibration() {
|
Calibration& ServoState::calibration() {
|
||||||
|
|
|
@ -51,21 +51,21 @@ namespace servo {
|
||||||
float _enable(); // Internal version of enable without convenient initialisation to the middle
|
float _enable(); // Internal version of enable without convenient initialisation to the middle
|
||||||
public:
|
public:
|
||||||
float get_pulse() const;
|
float get_pulse() const;
|
||||||
float set_pulse(float pulse);
|
float set_pulse_with_return(float pulse);
|
||||||
|
|
||||||
float get_value() const;
|
float get_value() const;
|
||||||
float set_value(float value);
|
float set_value_with_return(float value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float get_min_value() const;
|
float get_min_value() const;
|
||||||
float get_mid_value() const;
|
float get_mid_value() const;
|
||||||
float get_max_value() const;
|
float get_max_value() const;
|
||||||
|
|
||||||
float to_min();
|
float to_min_with_return();
|
||||||
float to_mid();
|
float to_mid_with_return();
|
||||||
float to_max();
|
float to_max_with_return();
|
||||||
float to_percent(float in, float in_min = ZERO_PERCENT, float in_max = ONEHUNDRED_PERCENT);
|
float to_percent_with_return(float in, float in_min = ZERO_PERCENT, float in_max = ONEHUNDRED_PERCENT);
|
||||||
float to_percent(float in, float in_min, float in_max, float value_min, float value_max);
|
float to_percent_with_return(float in, float in_min, float in_max, float value_min, float value_max);
|
||||||
|
|
||||||
Calibration& calibration();
|
Calibration& calibration();
|
||||||
const Calibration& calibration() const;
|
const Calibration& calibration() const;
|
||||||
|
|
|
@ -65,7 +65,7 @@ int main() {
|
||||||
for(auto i = 0u; i < 360; i++) {
|
for(auto i = 0u; i < 360; i++) {
|
||||||
float value = sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT;
|
float value = sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT;
|
||||||
for(auto s = 0u; s < NUM_SERVOS; s++) {
|
for(auto s = 0u; s < NUM_SERVOS; s++) {
|
||||||
servos[s]->set_value(value);
|
servos[s]->value(value);
|
||||||
}
|
}
|
||||||
sleep_ms(20);
|
sleep_ms(20);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ int main() {
|
||||||
// Do a sine sweep
|
// Do a sine sweep
|
||||||
for(auto j = 0u; j < SWEEPS; j++) {
|
for(auto j = 0u; j < SWEEPS; j++) {
|
||||||
for(auto i = 0u; i < 360; i++) {
|
for(auto i = 0u; i < 360; i++) {
|
||||||
servos.set_all_values(sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT);
|
servos.all_to_value(sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT);
|
||||||
sleep_ms(20);
|
sleep_ms(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,9 +60,9 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all the Servos
|
// Update all the Servos
|
||||||
for(auto i = 0u; i < servos.get_count(); i++) {
|
for(auto i = 0u; i < servos.count(); i++) {
|
||||||
float angle = (((float)i / (float)servos.get_count()) + offset) * (float)M_TWOPI;
|
float angle = (((float)i / (float)servos.count()) + offset) * (float)M_TWOPI;
|
||||||
servos.set_value(i, sin(angle) * SERVO_EXTENT, false);
|
servos.value(i, sin(angle) * SERVO_EXTENT, false);
|
||||||
}
|
}
|
||||||
// We have now set all the servo values, so load them
|
// We have now set all the servo values, so load them
|
||||||
servos.load();
|
servos.load();
|
||||||
|
|
|
@ -40,7 +40,7 @@ int main() {
|
||||||
s.init();
|
s.init();
|
||||||
|
|
||||||
// Get the initial value and create a random end value between the extents
|
// Get the initial value and create a random end value between the extents
|
||||||
float start_value = s.get_mid_value();
|
float start_value = s.mid_value();
|
||||||
float end_value = (((float)rand() / (float)RAND_MAX) * (SERVO_EXTENT * 2.0f)) - SERVO_EXTENT;
|
float end_value = (((float)rand() / (float)RAND_MAX) * (SERVO_EXTENT * 2.0f)) - SERVO_EXTENT;
|
||||||
|
|
||||||
uint update = 0;
|
uint update = 0;
|
||||||
|
@ -61,7 +61,7 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print out the value the servo is now at
|
// Print out the value the servo is now at
|
||||||
printf("Value = %f\n", s.get_value());
|
printf("Value = %f\n", s.value());
|
||||||
|
|
||||||
// Move along in time
|
// Move along in time
|
||||||
update++;
|
update++;
|
||||||
|
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
// Do a sine sweep
|
// Do a sine sweep
|
||||||
for(auto j = 0u; j < SWEEPS; j++) {
|
for(auto j = 0u; j < SWEEPS; j++) {
|
||||||
for(auto i = 0u; i < 360; i++) {
|
for(auto i = 0u; i < 360; i++) {
|
||||||
s.set_value(sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT);
|
s.value(sin(((float)i * (float)M_PI) / 180.0f) * SWEEP_EXTENT);
|
||||||
sleep_ms(20);
|
sleep_ms(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -837,15 +837,15 @@ void Servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind
|
||||||
mp_print_str(print, "Servo(");
|
mp_print_str(print, "Servo(");
|
||||||
|
|
||||||
mp_print_str(print, "pin = ");
|
mp_print_str(print, "pin = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_int(self->servo->get_pin()), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_int(self->servo->pin()), PRINT_REPR);
|
||||||
mp_print_str(print, ", enabled = ");
|
mp_print_str(print, ", enabled = ");
|
||||||
mp_obj_print_helper(print, self->servo->is_enabled() ? mp_const_true : mp_const_false, PRINT_REPR);
|
mp_obj_print_helper(print, self->servo->is_enabled() ? mp_const_true : mp_const_false, PRINT_REPR);
|
||||||
mp_print_str(print, ", pulse = ");
|
mp_print_str(print, ", pulse = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->servo->get_pulse()), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->servo->pulse()), PRINT_REPR);
|
||||||
mp_print_str(print, ", value = ");
|
mp_print_str(print, ", value = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->servo->get_value()), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->servo->value()), PRINT_REPR);
|
||||||
mp_print_str(print, ", freq = ");
|
mp_print_str(print, ", freq = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->servo->get_frequency()), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->servo->frequency()), PRINT_REPR);
|
||||||
|
|
||||||
mp_print_str(print, ")");
|
mp_print_str(print, ")");
|
||||||
}
|
}
|
||||||
|
@ -916,7 +916,7 @@ mp_obj_t Servo___del__(mp_obj_t self_in) {
|
||||||
/***** Methods *****/
|
/***** Methods *****/
|
||||||
extern mp_obj_t Servo_pin(mp_obj_t self_in) {
|
extern mp_obj_t Servo_pin(mp_obj_t self_in) {
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
||||||
return mp_obj_new_int(self->servo->get_pin());
|
return mp_obj_new_int(self->servo->pin());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t Servo_enable(mp_obj_t self_in) {
|
extern mp_obj_t Servo_enable(mp_obj_t self_in) {
|
||||||
|
@ -949,7 +949,7 @@ extern mp_obj_t Servo_pulse(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||||
|
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
||||||
|
|
||||||
return mp_obj_new_float(self->servo->get_pulse());
|
return mp_obj_new_float(self->servo->pulse());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_pulse };
|
enum { ARG_self, ARG_pulse };
|
||||||
|
@ -966,7 +966,7 @@ extern mp_obj_t Servo_pulse(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||||
|
|
||||||
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
||||||
|
|
||||||
self->servo->set_pulse(pulse);
|
self->servo->pulse(pulse);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -984,7 +984,7 @@ extern mp_obj_t Servo_value(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||||
|
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
||||||
|
|
||||||
return mp_obj_new_float(self->servo->get_value());
|
return mp_obj_new_float(self->servo->value());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_value };
|
enum { ARG_self, ARG_value };
|
||||||
|
@ -1001,7 +1001,7 @@ extern mp_obj_t Servo_value(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||||
|
|
||||||
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
||||||
|
|
||||||
self->servo->set_value(value);
|
self->servo->value(value);
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1019,7 @@ extern mp_obj_t Servo_frequency(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||||
|
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _Servo_obj_t);
|
||||||
|
|
||||||
return mp_obj_new_float(self->servo->get_frequency());
|
return mp_obj_new_float(self->servo->frequency());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_freq };
|
enum { ARG_self, ARG_freq };
|
||||||
|
@ -1036,7 +1036,7 @@ extern mp_obj_t Servo_frequency(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||||
|
|
||||||
float freq = mp_obj_get_float(args[ARG_freq].u_obj);
|
float freq = mp_obj_get_float(args[ARG_freq].u_obj);
|
||||||
|
|
||||||
if(!self->servo->set_frequency(freq)) {
|
if(!self->servo->frequency(freq)) {
|
||||||
mp_raise_ValueError("freq out of range. Expected 10Hz to 350Hz");
|
mp_raise_ValueError("freq out of range. Expected 10Hz to 350Hz");
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
|
@ -1045,17 +1045,17 @@ extern mp_obj_t Servo_frequency(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||||
|
|
||||||
extern mp_obj_t Servo_min_value(mp_obj_t self_in) {
|
extern mp_obj_t Servo_min_value(mp_obj_t self_in) {
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
||||||
return mp_obj_new_float(self->servo->get_min_value());
|
return mp_obj_new_float(self->servo->min_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t Servo_mid_value(mp_obj_t self_in) {
|
extern mp_obj_t Servo_mid_value(mp_obj_t self_in) {
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
||||||
return mp_obj_new_float(self->servo->get_mid_value());
|
return mp_obj_new_float(self->servo->mid_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t Servo_max_value(mp_obj_t self_in) {
|
extern mp_obj_t Servo_max_value(mp_obj_t self_in) {
|
||||||
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
_Servo_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Servo_obj_t);
|
||||||
return mp_obj_new_float(self->servo->get_max_value());
|
return mp_obj_new_float(self->servo->max_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t Servo_to_min(mp_obj_t self_in) {
|
extern mp_obj_t Servo_to_min(mp_obj_t self_in) {
|
||||||
|
@ -1212,18 +1212,18 @@ void ServoCluster_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
||||||
|
|
||||||
mp_print_str(print, "servos = {");
|
mp_print_str(print, "servos = {");
|
||||||
|
|
||||||
uint8_t servo_count = self->cluster->get_count();
|
uint8_t servo_count = self->cluster->count();
|
||||||
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
for(uint8_t servo = 0; servo < servo_count; servo++) {
|
||||||
mp_print_str(print, "\n\t{pin = ");
|
mp_print_str(print, "\n\t{pin = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_int(self->cluster->get_pin(servo)), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_int(self->cluster->pin(servo)), PRINT_REPR);
|
||||||
mp_print_str(print, ", enabled = ");
|
mp_print_str(print, ", enabled = ");
|
||||||
mp_obj_print_helper(print, self->cluster->is_enabled(servo) ? mp_const_true : mp_const_false, PRINT_REPR);
|
mp_obj_print_helper(print, self->cluster->is_enabled(servo) ? mp_const_true : mp_const_false, PRINT_REPR);
|
||||||
mp_print_str(print, ", pulse = ");
|
mp_print_str(print, ", pulse = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->get_pulse(servo)), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->pulse(servo)), PRINT_REPR);
|
||||||
mp_print_str(print, ", value = ");
|
mp_print_str(print, ", value = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->get_value(servo)), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->value(servo)), PRINT_REPR);
|
||||||
mp_print_str(print, ", phase = ");
|
mp_print_str(print, ", phase = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->get_phase(servo)), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->phase(servo)), PRINT_REPR);
|
||||||
mp_print_str(print, "}");
|
mp_print_str(print, "}");
|
||||||
if(servo < servo_count - 1)
|
if(servo < servo_count - 1)
|
||||||
mp_print_str(print, ", ");
|
mp_print_str(print, ", ");
|
||||||
|
@ -1232,7 +1232,7 @@ void ServoCluster_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
||||||
mp_print_str(print, "\n");
|
mp_print_str(print, "\n");
|
||||||
}
|
}
|
||||||
mp_print_str(print, "}, freq = ");
|
mp_print_str(print, "}, freq = ");
|
||||||
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->get_frequency()), PRINT_REPR);
|
mp_obj_print_helper(print, mp_obj_new_float(self->cluster->frequency()), PRINT_REPR);
|
||||||
|
|
||||||
mp_print_str(print, ")");
|
mp_print_str(print, ")");
|
||||||
}
|
}
|
||||||
|
@ -1377,7 +1377,7 @@ mp_obj_t ServoCluster___del__(mp_obj_t self_in) {
|
||||||
/***** Methods *****/
|
/***** Methods *****/
|
||||||
extern mp_obj_t ServoCluster_count(mp_obj_t self_in) {
|
extern mp_obj_t ServoCluster_count(mp_obj_t self_in) {
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(self_in, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(self_in, _ServoCluster_obj_t);
|
||||||
return mp_obj_new_int(self->cluster->get_count());
|
return mp_obj_new_int(self->cluster->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t ServoCluster_pin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
extern mp_obj_t ServoCluster_pin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
|
@ -1394,13 +1394,13 @@ extern mp_obj_t ServoCluster_pin(size_t n_args, const mp_obj_t *pos_args, mp_map
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_int(self->cluster->get_pin((uint)servo));
|
return mp_obj_new_int(self->cluster->pin((uint)servo));
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -1419,7 +1419,7 @@ extern mp_obj_t ServoCluster_enable(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -1503,7 +1503,7 @@ extern mp_obj_t ServoCluster_disable(size_t n_args, const mp_obj_t *pos_args, mp
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -1587,7 +1587,7 @@ extern mp_obj_t ServoCluster_is_enabled(size_t n_args, const mp_obj_t *pos_args,
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
|
@ -1613,13 +1613,13 @@ extern mp_obj_t ServoCluster_pulse(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_pulse((uint)servo));
|
return mp_obj_new_float(self->cluster->pulse((uint)servo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_servos, ARG_pulse, ARG_load };
|
enum { ARG_self, ARG_servos, ARG_pulse, ARG_load };
|
||||||
|
@ -1636,7 +1636,7 @@ extern mp_obj_t ServoCluster_pulse(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -1648,7 +1648,7 @@ extern mp_obj_t ServoCluster_pulse(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else {
|
else {
|
||||||
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
||||||
self->cluster->set_pulse((uint)servo, pulse, args[ARG_load].u_bool);
|
self->cluster->pulse((uint)servo, pulse, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1683,7 +1683,7 @@ extern mp_obj_t ServoCluster_pulse(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
||||||
self->cluster->set_pulse(servos, length, pulse, args[ARG_load].u_bool);
|
self->cluster->pulse(servos, length, pulse, args[ARG_load].u_bool);
|
||||||
delete[] servos;
|
delete[] servos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1693,30 +1693,6 @@ extern mp_obj_t ServoCluster_pulse(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t ServoCluster_all_to_pulse(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
extern mp_obj_t ServoCluster_all_to_pulse(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
/*if(n_args <= 1) {
|
|
||||||
enum { ARG_self };
|
|
||||||
static const mp_arg_t allowed_args[] = {
|
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse args.
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
||||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
|
||||||
|
|
||||||
uint servo_count = self->cluster->get_count();
|
|
||||||
if(servo_count == 0)
|
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
|
||||||
else {
|
|
||||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR2(mp_obj_new_tuple(servo_count, NULL), mp_obj_tuple_t);
|
|
||||||
for(uint servo = 0; servo < servo_count; servo++) {
|
|
||||||
tuple->items[servo] = mp_obj_new_float(self->cluster->get_pulse(servo));
|
|
||||||
}
|
|
||||||
return MP_OBJ_FROM_PTR(tuple);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {*/
|
|
||||||
enum { ARG_self, ARG_pulse, ARG_load };
|
enum { ARG_self, ARG_pulse, ARG_load };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
|
@ -1730,14 +1706,13 @@ extern mp_obj_t ServoCluster_all_to_pulse(size_t n_args, const mp_obj_t *pos_arg
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
float pulse = mp_obj_get_float(args[ARG_pulse].u_obj);
|
||||||
self->cluster->set_all_pulses(pulse, args[ARG_load].u_bool);
|
self->cluster->all_to_pulse(pulse, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1756,13 +1731,13 @@ extern mp_obj_t ServoCluster_value(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_value((uint)servo));
|
return mp_obj_new_float(self->cluster->value((uint)servo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_servos, ARG_value, ARG_load };
|
enum { ARG_self, ARG_servos, ARG_value, ARG_load };
|
||||||
|
@ -1779,7 +1754,7 @@ extern mp_obj_t ServoCluster_value(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -1791,7 +1766,7 @@ extern mp_obj_t ServoCluster_value(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else {
|
else {
|
||||||
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
||||||
self->cluster->set_value((uint)servo, value, args[ARG_load].u_bool);
|
self->cluster->value((uint)servo, value, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1826,7 +1801,7 @@ extern mp_obj_t ServoCluster_value(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
||||||
self->cluster->set_value(servos, length, value, args[ARG_load].u_bool);
|
self->cluster->value(servos, length, value, args[ARG_load].u_bool);
|
||||||
delete[] servos;
|
delete[] servos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1836,30 +1811,6 @@ extern mp_obj_t ServoCluster_value(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t ServoCluster_all_to_value(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
extern mp_obj_t ServoCluster_all_to_value(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
/*if(n_args <= 1) {
|
|
||||||
enum { ARG_self, ARG_servo };
|
|
||||||
static const mp_arg_t allowed_args[] = {
|
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse args.
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
||||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
|
||||||
|
|
||||||
uint servo_count = self->cluster->get_count();
|
|
||||||
if(servo_count == 0)
|
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
|
||||||
else {
|
|
||||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR2(mp_obj_new_tuple(servo_count, NULL), mp_obj_tuple_t);
|
|
||||||
for(uint servo = 0; servo < servo_count; servo++) {
|
|
||||||
tuple->items[servo] = mp_obj_new_float(self->cluster->get_value(servo));
|
|
||||||
}
|
|
||||||
return MP_OBJ_FROM_PTR(tuple);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {*/
|
|
||||||
enum { ARG_self, ARG_value, ARG_load };
|
enum { ARG_self, ARG_value, ARG_load };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
|
@ -1873,14 +1824,13 @@ extern mp_obj_t ServoCluster_all_to_value(size_t n_args, const mp_obj_t *pos_arg
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
float value = mp_obj_get_float(args[ARG_value].u_obj);
|
||||||
self->cluster->set_all_values(value, args[ARG_load].u_bool);
|
self->cluster->all_to_value(value, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1899,13 +1849,13 @@ extern mp_obj_t ServoCluster_phase(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_phase((uint)servo));
|
return mp_obj_new_float(self->cluster->phase((uint)servo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_servos, ARG_phase, ARG_load };
|
enum { ARG_self, ARG_servos, ARG_phase, ARG_load };
|
||||||
|
@ -1922,7 +1872,7 @@ extern mp_obj_t ServoCluster_phase(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -1934,7 +1884,7 @@ extern mp_obj_t ServoCluster_phase(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else {
|
else {
|
||||||
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
||||||
self->cluster->set_phase((uint)servo, phase, args[ARG_load].u_bool);
|
self->cluster->phase((uint)servo, phase, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1969,7 +1919,7 @@ extern mp_obj_t ServoCluster_phase(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
||||||
self->cluster->set_phase(servos, length, phase, args[ARG_load].u_bool);
|
self->cluster->phase(servos, length, phase, args[ARG_load].u_bool);
|
||||||
delete[] servos;
|
delete[] servos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1979,30 +1929,6 @@ extern mp_obj_t ServoCluster_phase(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_obj_t ServoCluster_all_to_phase(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
extern mp_obj_t ServoCluster_all_to_phase(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
/*if(n_args <= 1) {
|
|
||||||
enum { ARG_self };
|
|
||||||
static const mp_arg_t allowed_args[] = {
|
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse args.
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
||||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
|
||||||
|
|
||||||
uint servo_count = self->cluster->get_count();
|
|
||||||
if(servo_count == 0)
|
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
|
||||||
else {
|
|
||||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR2(mp_obj_new_tuple(servo_count, NULL), mp_obj_tuple_t);
|
|
||||||
for(uint servo = 0; servo < servo_count; servo++) {
|
|
||||||
tuple->items[servo] = mp_obj_new_float(self->cluster->get_phase(servo));
|
|
||||||
}
|
|
||||||
return MP_OBJ_FROM_PTR(tuple);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {*/
|
|
||||||
enum { ARG_self, ARG_phase, ARG_load };
|
enum { ARG_self, ARG_phase, ARG_load };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||||
|
@ -2016,14 +1942,13 @@ extern mp_obj_t ServoCluster_all_to_phase(size_t n_args, const mp_obj_t *pos_arg
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
float phase = mp_obj_get_float(args[ARG_phase].u_obj);
|
||||||
self->cluster->set_all_phases(phase, args[ARG_load].u_bool);
|
self->cluster->all_to_phase(phase, args[ARG_load].u_bool);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2040,7 +1965,7 @@ extern mp_obj_t ServoCluster_frequency(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
return mp_obj_new_float(self->cluster->get_frequency());
|
return mp_obj_new_float(self->cluster->frequency());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
enum { ARG_self, ARG_freq };
|
enum { ARG_self, ARG_freq };
|
||||||
|
@ -2057,7 +1982,7 @@ extern mp_obj_t ServoCluster_frequency(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
float freq = mp_obj_get_float(args[ARG_freq].u_obj);
|
float freq = mp_obj_get_float(args[ARG_freq].u_obj);
|
||||||
|
|
||||||
if(!self->cluster->set_frequency(freq))
|
if(!self->cluster->frequency(freq))
|
||||||
mp_raise_ValueError("freq out of range. Expected 10Hz to 350Hz");
|
mp_raise_ValueError("freq out of range. Expected 10Hz to 350Hz");
|
||||||
else
|
else
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
|
@ -2078,13 +2003,13 @@ extern mp_obj_t ServoCluster_min_value(size_t n_args, const mp_obj_t *pos_args,
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_min_value((uint)servo));
|
return mp_obj_new_float(self->cluster->min_value((uint)servo));
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -2103,13 +2028,13 @@ extern mp_obj_t ServoCluster_mid_value(size_t n_args, const mp_obj_t *pos_args,
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_mid_value((uint)servo));
|
return mp_obj_new_float(self->cluster->mid_value((uint)servo));
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -2128,13 +2053,13 @@ extern mp_obj_t ServoCluster_max_value(size_t n_args, const mp_obj_t *pos_args,
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("servo out of range. Expected 0 to %d"), servo_count - 1);
|
||||||
else
|
else
|
||||||
return mp_obj_new_float(self->cluster->get_max_value((uint)servo));
|
return mp_obj_new_float(self->cluster->max_value((uint)servo));
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -2153,7 +2078,7 @@ extern mp_obj_t ServoCluster_to_min(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2218,7 +2143,7 @@ extern mp_obj_t ServoCluster_all_to_min(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2241,7 +2166,7 @@ extern mp_obj_t ServoCluster_to_mid(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2306,7 +2231,7 @@ extern mp_obj_t ServoCluster_all_to_mid(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2329,7 +2254,7 @@ extern mp_obj_t ServoCluster_to_max(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2394,7 +2319,7 @@ extern mp_obj_t ServoCluster_all_to_max(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2419,7 +2344,7 @@ extern mp_obj_t ServoCluster_to_percent(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2489,7 +2414,7 @@ extern mp_obj_t ServoCluster_to_percent(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2565,7 +2490,7 @@ extern mp_obj_t ServoCluster_to_percent(size_t n_args, const mp_obj_t *pos_args,
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2644,7 +2569,7 @@ extern mp_obj_t ServoCluster_all_to_percent(size_t n_args, const mp_obj_t *pos_a
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2668,7 +2593,7 @@ extern mp_obj_t ServoCluster_all_to_percent(size_t n_args, const mp_obj_t *pos_a
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2696,7 +2621,7 @@ extern mp_obj_t ServoCluster_all_to_percent(size_t n_args, const mp_obj_t *pos_a
|
||||||
|
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else {
|
else {
|
||||||
|
@ -2726,7 +2651,7 @@ extern mp_obj_t ServoCluster_calibration(size_t n_args, const mp_obj_t *pos_args
|
||||||
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
_ServoCluster_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _ServoCluster_obj_t);
|
||||||
|
|
||||||
int servo = args[ARG_servo].u_int;
|
int servo = args[ARG_servo].u_int;
|
||||||
int servo_count = (int)self->cluster->get_count();
|
int servo_count = (int)self->cluster->count();
|
||||||
if(servo_count == 0)
|
if(servo_count == 0)
|
||||||
mp_raise_ValueError("this cluster does not have any servos");
|
mp_raise_ValueError("this cluster does not have any servos");
|
||||||
else if(servo < 0 || servo >= servo_count)
|
else if(servo < 0 || servo >= servo_count)
|
||||||
|
|
Ładowanie…
Reference in New Issue