Some tips on how to create a device for a new motor control board.
#include <cstdio>
public DeviceDriver,
public IPositionControl
{
public:
{
*ax = 2;
printf("FakeMotor reporting %d axes present\n", *ax);
return true;
}
{
return true;
}
{
return true;
}
bool positionMove(
const int n_joint,
const int* joints,
const double* refs)
override
{
return true;
}
{
return true;
}
{
return true;
}
bool relativeMove(
const int n_joint,
const int* joints,
const double* deltas)
override
{
return true;
}
{
return true;
}
{
return true;
}
bool checkMotionDone(
const int n_joint,
const int* joints,
bool* flag)
override
{
return true;
}
{
return true;
}
{
return true;
}
bool setRefSpeeds(
const int n_joint,
const int* joints,
const double* spds)
override
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
bool getRefSpeeds(
const int n_joint,
const int* joints,
double* spds)
override
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
bool stop(
int j)
override
{
return true;
}
{
return true;
}
bool stop(
const int n_joint,
const int* joints)
override
{
return true;
}
bool open(Searchable& config)
override
{
return true;
}
{
return true;
}
};
void testMotor(PolyDriver& driver)
{
IPositionControl* pos;
if (driver.view(pos)) {
int ct = 0;
pos->getAxes(&ct);
printf(" number of axes is: %d\n", ct);
} else {
printf(" could not find IPositionControl interface\n");
}
}
int main(
int argc,
char* argv[])
{
Drivers::factory().add(new DriverCreatorOf<FakeMotor>("motor",
"controlboard",
"FakeMotor"));
printf("============================================================\n");
printf("check our device can be instantiated directly\n");
PolyDriver direct("motor");
if (direct.isValid()) {
printf("Direct instantiation worked\n");
testMotor(direct);
} else {
printf("Direct instantiation failed\n");
}
direct.close();
printf("\n\n");
printf("============================================================\n");
printf("check our device can be wrapped in controlboard\n");
PolyDriver indirect("(device controlboard) (subdevice motor)");
if (indirect.isValid()) {
printf("Indirect instantiation worked\n");
} else {
printf("Indirect instantiation failed\n");
}
indirect.close();
printf("\n\n");
printf("============================================================\n");
printf("check our device can be accessed via remote_controlboard\n");
PolyDriver server("(device controlboard) (subdevice motor) (name /server)");
if (server.isValid()) {
printf("Server instantiation worked\n");
PolyDriver client("(device clientcontrolboard) (local /client) (remote /server)");
if (client.isValid()) {
printf("Client instantiation worked\n");
testMotor(client);
} else {
printf("Client instantiation failed\n");
}
client.close();
}
server.close();
return 0;
}