YARP
Yet Another Robot Platform
dev/motortest.cpp

Example showing how to use the SerialServoBoard driver AND how to configure and use the IPositionControl interface./**

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <yarp/os/Port.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/Time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace yarp::os;
using namespace yarp::dev;
int main(int argc, char *argv[]) {
if(argc!=7) {
printf(" Error: correct usage is %s --board BOARD --comport COM --baudrate BAUDRATE\n", argv[0]);
printf(" BOARD is one out of ssc32, minissc, pontech_sv203x, mondotronic_smi, pololu_usb_16servo, picopic\n");
printf(" COM is COMx or /dev/ttyS0\n");
printf(" BAUDRATE is the baud rate, eg: 38400");
return 1;
}
Property config;
config.fromCommand(argc, argv);
Property options;
//options.put("robot", "icub"); // typically from the command line.
options.put("device", "SerialServoBoard");
options.put("board", config.check("board", yarp::os::Value("ssc32")).asString().c_str());
options.put("comport", config.check("comport", yarp::os::Value("/dev/ttyS0")).asString().c_str());
options.put("baudrate", config.check("baudrate", yarp::os::Value(38400)).asInt32());
PolyDriver dd(options);
if(!dd.isValid()) {
printf("Device not available.\n");
return 1;
}
dd.view(pos);
int jnts = 0;
pos->getAxes(&jnts);
//printf("axes: %d\n", jnts);
//Time::delay(1);
pos->positionMove(0, -45);
dd.close();
return 0;
}
yarp::os::Property::put
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:998
Network.h
yarp::dev::IPositionControl::positionMove
virtual bool positionMove(int j, double ref)=0
Set new reference point for a single axis.
yarp::os::Network::fini
static void fini()
Deinitialization.
Port.h
yarp::dev::PolyDriver::isValid
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:194
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:259
yarp::dev::DeviceDriver::view
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:77
ControlBoardInterfaces.h
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::os::Property::fromCommand
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Definition: Property.cpp:1057
PolyDriver.h
yarp::dev::PolyDriver
Definition: PolyDriver.h:25
yarp::dev::PolyDriver::close
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:171
yarp::os::Property::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1024
yarp::dev::IPositionControl::getAxes
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
yarp::os
Definition: AbstractCarrier.h:17
yarp::os::Network
Definition: Network.h:781
yarp
Definition: numeric.h:47
Time.h
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:46
yarp::dev::IPositionControl
Definition: IPositionControl.h:256
yarp::os::Time::delay
void delay(double seconds)
Wait for a certain number of seconds.
Definition: Time.cpp:114
Bottle.h
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:34