spot-sdk-js
Version:
Develop applications and payloads for Spot using the unofficial Boston Dynamics Spot Node.js SDK.
143 lines (115 loc) • 5.55 kB
JavaScript
const {BaseClient} = require('../common');
const {recenter_angle} = require('../math_helpers');
const service_grpc_pb = require('../../bosdyn/api/spot_cam/service_grpc_pb');
const ptz_pb = require('../../bosdyn/api/spot_cam/ptz_pb');
const {FloatValue} = require('google-protobuf/google/protobuf/wrappers_pb');
class PtzClient extends BaseClient {
static default_service_name = 'spot-cam-ptz';
static service_type = 'bosdyn.api.spot_cam.PtzService';
constructor(){
super(service_grpc_pb.PtzServiceClient);
}
async list_ptz(args){
const request = new ptz_pb.ListPtzRequest();
return await this.call(this._stub.listPtz, request, this._list_ptz_from_response, this._ptz_error_from_response, args);
}
list_ptz_async(args){
const request = new ptz_pb.ListPtzRequest();
return this.call_async(this._stub.ListPtz, request, this._list_ptz_from_response, this._ptz_error_from_response, args);
}
async get_ptz_position(ptz_desc, args){
const request = new ptz_pb.GetPtzPositionRequest().setPtz(ptz_desc);
return await this.call(this._stub.getPtzPosition, request, this._get_ptz_position_from_response, this._ptz_error_from_response, args);
}
get_ptz_position_async(ptz_desc, args){
const request = new ptz_pb.GetPtzPositionRequest().setPtz(ptz_desc);
return this.call_async(this._stub.getPtzPosition, request, this._get_ptz_position_from_response, this._ptz_error_from_response, args);
}
async get_ptz_velocity(ptz_desc, args){
const request = new ptz_pb.GetPtzVelocityRequest().setPtz(ptz_desc);
return await this.call(this._stub.getPtzVelocity, request, this._get_ptz_velocity_from_response, this._ptz_error_from_response, args);
}
get_ptz_velocity_async(ptz_desc, args){
const request = new ptz_pb.GetPtzVelocityRequest().setPtz(ptz_desc);
return this.call_async(this._stub.getPtzVelocity, request, this._get_ptz_velocity_from_response, this._ptz_error_from_response, args);
}
async set_ptz_position(ptz_desc, pan, tilt, zoom, args){
const p = new FloatValue().setValue(pan);
const t = new FloatValue().setValue(tilt);
const z = new FloatValue().setValue(zoom);
const ptz_position = new ptz_pb.PtzPosition().setPtz(ptz_desc).setPan(p).setTilt(t).setZoom(z);
const request = new ptz_pb.SetPtzPositionRequest().setPosition(ptz_position);
return await this.call(this._stub.setPtzPosition, request, this._set_ptz_position_from_response, this._ptz_error_from_response, args);
}
set_ptz_position_async(ptz_desc, pan, tilt, zoom, args){
const p = new FloatValue().setValue(pan);
const t = new FloatValue().setValue(tilt);
const z = new FloatValue().setValue(zoom);
const ptz_position = new ptz_pb.PtzPosition().setPtz(ptz_desc).setPan(p).setTilt(t).setZoom(z);
const request = new ptz_pb.SetPtzPositionRequest().setPosition(ptz_position);
return this.call_async(this._stub.setPtzPosition, request, this._set_ptz_position_from_response, this._ptz_error_from_response, args);
}
async set_ptz_velocity(ptz_desc, pan, tilt, zoom, args){
const p = new FloatValue().setValue(pan);
const t = new FloatValue().setValue(tilt);
const z = new FloatValue().setValue(zoom);
const ptz_velocity = new ptz_pb.PtzVelocity().setPtz(ptz_desc).setPan(p).setTilt(t).setZoom(z);
const request = new ptz_pb.SetPtzVelocityRequest().setVelocity(ptz_velocity);
return await this.call(this._stub.setPtzVelocity, request, this._set_ptz_velocity_from_response, this._ptz_error_from_response, args);
}
set_ptz_velocity_async(ptz_desc, pan, tilt, zoom, args){
const p = new FloatValue().setValue(pan);
const t = new FloatValue().setValue(tilt);
const z = new FloatValue().setValue(zoom);
const ptz_velocity = new ptz_pb.PtzVelocity().setPtz(ptz_desc).setPan(p).setTilt(t).setZoom(z);
const request = new ptz_pb.SetPtzVelocityRequest().setVelocity(ptz_velocity);
return this.call_async(this._stub.setPtzVelocity, request, this._set_ptz_velocity_from_response, this._ptz_error_from_response, args);
}
async initialize_lens(args){
const request = new ptz_pb.InitializeLensRequest();
return await this.call(this._stub.initializeLens, request, this._initialize_lens_from_response, common_header_errors, args);
}
initialize_lens_async(args){
const request = new ptz_pb.InitializeLensRequest();
return this.call_async(this._stub.initializeLens, request, this._initialize_lens_from_response, common_header_errors, args);
}
_list_ptz_from_response(response){
return response.getPtzsList();
}
_get_ptz_position_from_response(response){
return response.getPosition();
}
_get_ptz_velocity_from_response(response){
return response.getVelocity();
}
_set_ptz_position_from_response(response){
return response.getPosition();
}
_set_ptz_velocity_from_response(response){
return response.getVelocity();
}
_ptz_error_from_response(response){
return null;
}
_initialize_lens_from_response(response){
return response;
}
_get_ptz_focus_from_response(response){
return response.getPtzFocus();
}
_set_ptz_focus_from_response(response){
return response.getPtzFocus();
}
};
/**
* Shift the pan angle (degrees) so that it is in the [0,360] range.
* @param {number} pan
* @returns {number}
*/
function shift_pan_angle(pan){
return recenter_angle(pan, 0, 360);
}
module.exports = {
PtzClient,
shift_pan_angle
};