2016-10-28 19:05:19 -03:00
|
|
|
#include <AP_Gripper/AP_Gripper_Servo.h>
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
void AP_Gripper_Servo::init_gripper()
|
|
|
|
{
|
|
|
|
// move the servo to the release position
|
2016-11-17 23:12:58 -04:00
|
|
|
release();
|
2016-10-28 19:05:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_Gripper_Servo::grab()
|
|
|
|
{
|
2016-11-17 23:12:58 -04:00
|
|
|
// move the servo to the grab position
|
2017-01-06 21:06:40 -04:00
|
|
|
SRV_Channels::set_output_pwm(SRV_Channel::k_gripper, config.grab_pwm);
|
2016-11-17 23:12:58 -04:00
|
|
|
action_timestamp = AP_HAL::millis();
|
2016-10-28 19:05:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_Gripper_Servo::release()
|
|
|
|
{
|
|
|
|
// move the servo to the release position
|
2017-01-06 21:06:40 -04:00
|
|
|
SRV_Channels::set_output_pwm(SRV_Channel::k_gripper, config.release_pwm);
|
2016-11-17 23:12:58 -04:00
|
|
|
action_timestamp = AP_HAL::millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_Gripper_Servo::has_state_pwm(const uint16_t pwm) const
|
|
|
|
{
|
|
|
|
// return true if servo is in position represented by pwm
|
2017-01-06 21:06:40 -04:00
|
|
|
uint16_t current_pwm;
|
|
|
|
if (!SRV_Channels::get_output_pwm(SRV_Channel::k_gripper, current_pwm)) {
|
2016-11-17 23:12:58 -04:00
|
|
|
// function not assigned to a channel, perhaps?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (current_pwm != pwm) {
|
|
|
|
// last action did not set pwm to the current value
|
2016-12-18 23:14:19 -04:00
|
|
|
// (e.g. last action was a grab not a release)
|
2016-11-17 23:12:58 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (AP_HAL::millis() - action_timestamp < action_time) {
|
|
|
|
// servo still moving....
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AP_Gripper_Servo::released() const
|
|
|
|
{
|
|
|
|
return has_state_pwm(config.release_pwm);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AP_Gripper_Servo::grabbed() const
|
|
|
|
{
|
|
|
|
return has_state_pwm(config.grab_pwm);
|
2016-10-28 19:05:19 -03:00
|
|
|
}
|
|
|
|
|
2016-11-17 23:12:58 -04:00
|
|
|
// type-specific periodic updates:
|
2016-10-28 19:05:19 -03:00
|
|
|
void AP_Gripper_Servo::update_gripper() { };
|
2016-12-19 23:18:18 -04:00
|
|
|
|
|
|
|
bool AP_Gripper_Servo::valid() const
|
|
|
|
{
|
|
|
|
if (!AP_Gripper_Backend::valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-06 21:06:40 -04:00
|
|
|
if (!SRV_Channels::function_assigned(SRV_Channel::k_gripper)) {
|
2016-12-19 23:18:18 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|