28 #ifndef QB_DEVICE_DRIVER_H 29 #define QB_DEVICE_DRIVER_H 52 commActivate(file_descriptor,
id, static_cast<char>(activate_command));
117 virtual void getParameters(
comm_settings *file_descriptor,
const int &
id, std::vector<int> &input_mode, std::vector<int> &control_mode, std::vector<int> &resolutions, std::vector<int> &limits) {
118 unsigned char parameter_buffer[5000];
122 getParameter<uint8_t>(5, parameter_buffer, input_mode);
123 getParameter<uint8_t>(6, parameter_buffer, control_mode);
124 getParameter<uint8_t>(7, parameter_buffer, resolutions);
125 getParameter<int32_t>(11, parameter_buffer, limits);
143 measurements.resize(5);
185 activate_status = status != 0;
210 openRS485(file_descriptor, serial_port.c_str());
254 commGetParamList(file_descriptor,
id, 2, pid.data(),
sizeof(float), pid.size(), NULL);
267 void getParameter(
const int ¶meter_id,
unsigned char *parameter_buffer, std::vector<int> ¶meter_vector) {
268 parameter_vector.clear();
269 int number_of_values = parameter_buffer[(parameter_id-1)*
PARAM_BYTE_SLOT + 7];
270 int value_size =
sizeof(T);
271 for (
int i=0; i<number_of_values; i++) {
272 T parameter_field = 0;
273 for (
int j=0; j<value_size; j++) {
274 parameter_field += parameter_buffer[(parameter_id-1)*
PARAM_BYTE_SLOT + 8 + i*value_size + value_size - j - 1] << (8 * j);
276 parameter_vector.push_back(parameter_field);
288 void getParameter(
const int ¶meter_id,
unsigned char *parameter_buffer, std::vector<float> ¶meter_vector) {
289 parameter_vector.clear();
290 int number_of_values = parameter_buffer[(parameter_id-1)*
PARAM_BYTE_SLOT + 7];
291 int value_size =
sizeof(T);
292 for (
int i=0; i<number_of_values; i++) {
293 std::vector<uint8_t> parameter_field(value_size, 0);
294 for (
int j=0; j<value_size; j++) {
295 parameter_field.at(j) = parameter_buffer[(parameter_id-1)*
PARAM_BYTE_SLOT + 8 + i*value_size + value_size - j - 1];
297 parameter_vector.push_back(*(reinterpret_cast<T*>(parameter_field.data())));
304 #endif // QB_DEVICE_DRIVER_H int commGetCurrents(comm_settings *comm_settings_t, int id, short int currents[2])
This function gets currents from a qbMove or a qbHand connected to the serial port.
void openRS485(comm_settings *comm_settings_t, const char *port_s, int BAUD_RATE=B2000000)
This function is used to open a serial port for using with the qbMove or the qbHand.
virtual int getPositions(comm_settings *file_descriptor, const int &id, std::vector< short int > &positions)
Retrieve the motor positions of the given device.
int RS485ListDevices(comm_settings *comm_settings_t, char list_of_ids[255])
This function is used to list the number of devices connected to the serial port and get their relati...
void closeRS485(comm_settings *comm_settings_t)
This function is used to close a serial port being used with the qbMove or an qbHand.
This class wraps the qbrobotics device-independent API to easily use it within the Communication Hand...
#define INFO_ALL
All system information.
int commGetParamList(comm_settings *comm_settings_t, int id, unsigned short index, void *values, unsigned short value_size, unsigned short num_of_values, uint8_t *buffer)
This function gets all the parameters that are stored in the qbMove or qbHand memory and sets one of ...
int commGetInfo(comm_settings *comm_settings_t, int id, short int info_type, char *info)
This function is used to ping the qbMove or the qbHand and get information about the device...
int commGetCurrAndMeas(comm_settings *comm_settings_t, int id, short int *values)
This function gets currents and position measurements from a qbMove or a qbHand connected to the seri...
virtual int getSerialPorts(std::array< char[255], 10 > &serial_ports)
Retrieve the list of serial ports connected to the system.
void getParameter(const int ¶meter_id, unsigned char *parameter_buffer, std::vector< int > ¶meter_vector)
Extract the specified parameter from the given buffer where all the device parameters are stored...
virtual bool getStatus(comm_settings *file_descriptor, const int &id)
Retrieve the connection status of the given device.
virtual void close(comm_settings *file_descriptor)
Close the communication with all the devices connected to the serial port relative to the given file ...
virtual void open(comm_settings *file_descriptor, const std::string &serial_port)
Open the serial communication on the given serial port.
virtual int setPID(comm_settings *file_descriptor, const int &id, std::vector< float > &pid)
Set the position control PID parameters of the given device, temporarily (until power off)...
virtual void getParameters(comm_settings *file_descriptor, const int &id, std::vector< int > &input_mode, std::vector< int > &control_mode, std::vector< int > &resolutions, std::vector< int > &limits)
Retrieve some of the parameters from the given device.
virtual bool getStatus(comm_settings *file_descriptor, const int &id, bool &activate_status)
Retrieve the motor activation status of the given device.
virtual std::string getInfo(comm_settings *file_descriptor, const int &id)
Retrieve the printable configuration setup of the given device.
void commSetInputs(comm_settings *comm_settings_t, int id, short int inputs[])
This function send reference inputs to a qbMove or a qbHand connected to the serial port...
Library of functions for SERIAL PORT communication with a qbMove.
virtual int setCommandsAndWait(comm_settings *file_descriptor, const int &id, std::vector< short int > &commands)
Send the reference command to the motors of the given device and wait for acknowledge.
virtual int getMeasurements(comm_settings *file_descriptor, const int &id, std::vector< short int > &measurements)
Retrieve the motor positions of the given device.
void getParameter(const int ¶meter_id, unsigned char *parameter_buffer, std::vector< float > ¶meter_vector)
Extract the specified parameter from the given buffer where all the device parameters are stored...
virtual int setCommandsAsync(comm_settings *file_descriptor, const int &id, std::vector< short int > &commands)
Send the reference command to the motors of the given device in a non-blocking fashion.
int RS485listPorts(char list_of_ports[10][255])
This function is used to return a list of available serial ports.
virtual int getCurrents(comm_settings *file_descriptor, const int &id, std::vector< short int > ¤ts)
Retrieve the motor currents of the given device.
int commGetActivate(comm_settings *comm_settings_t, int id, char *activate)
This function gets the activation status of a qbMove or a qbHand connected to the serial port...
virtual void activate(comm_settings *file_descriptor, const int &id, bool activate_command)
Activate (or deactivate, according to the given command) the motors of the device connected to the se...
virtual int getDeviceIds(comm_settings *file_descriptor, std::array< char, 255 > &device_ids)
Retrieve the list of devices connected to the serial port of the given file descriptor.
int commGetMeasurements(comm_settings *comm_settings_t, int id, short int measurements[3])
This function gets position measurements from a qbMove or a qbHand connected to the serial port...
int commSetInputsAck(comm_settings *comm_settings_t, int id, short int inputs[])
This function send reference inputs to a qbMove or a qbHand connected to the serial port and expects ...
std::shared_ptr< qbDeviceAPI > qbDeviceAPIPtr
void commActivate(comm_settings *comm_settings_t, int id, char activate)
This function activates or deactivates a qbMove or a qbHand connected to the serial port...