17constexpr
int MAX_ENTRIES = 255;
37 yCError(VIRTUALANALOGSERVER) <<
"Check configuration file top<base.";
57 yCError(VIRTUALANALOGSERVER) <<
"Wrong device" << key.c_str();
64 yCError(VIRTUALANALOGSERVER) <<
"'configure' should be called before you can attach any device";
70 yCError(VIRTUALANALOGSERVER) <<
"Invalid device (null pointer)";
82 yCError(VIRTUALANALOGSERVER) <<
"Invalid device " << key <<
" (isValid() returned false)";
110 mIsVerbose = (config.
check(
"verbose",
"if present, give detailed output"));
113 yCDebug(VIRTUALANALOGSERVER) <<
"Running with verbose output\n";
119 yCDebug(VIRTUALANALOGSERVER) <<
"Using VirtualAnalogServer\n";
121 if (!config.
check(
"networks",
"list of networks merged by this wrapper"))
123 yCError(VIRTUALANALOGSERVER) <<
"Missing networks parameters";
133 for (
int i = 0; i < MAX_ENTRIES; i++)
141 for (
size_t k=0; k<networks->
size(); ++k)
144 int map0, map1, map2, map3;
146 if (parameters.size() == 2)
153 tmpBot.
fromString(parameters.get(1).asString());
154 if (tmpBot.
size() != 4)
156 yCError(VIRTUALANALOGSERVER) <<
"Error: check network parameters in part description"
157 <<
"--> I was expecting" << networks->
get(k).
asString() <<
"followed by four integers between parentheses"
158 <<
"Got: " << parameters.toString();
166 map1 = bot->get(1).asInt32();
167 map2 = bot->get(2).asInt32();
168 map3 = bot->get(3).asInt32();
170 else if (parameters.size() == 5)
172 yCError(VIRTUALANALOGSERVER) <<
"Parameter networks use deprecated syntax";
173 map0 = parameters.get(1).asInt32();
174 map1 = parameters.get(2).asInt32();
175 map2 = parameters.get(3).asInt32();
176 map3 = parameters.get(4).asInt32();
180 yCError(VIRTUALANALOGSERVER) <<
"Error: check network parameters in part description"
181 <<
"--> I was expecting" << networks->
get(k).
asString() <<
"followed by four integers between parentheses"
182 <<
"Got: " << parameters.toString();
186 if (map0 >= MAX_ENTRIES || map1 >= MAX_ENTRIES || map2>= MAX_ENTRIES || map3>= MAX_ENTRIES ||
187 map0 <0 || map1 <0 || map2<0 || map3<0)
189 yCError(VIRTUALANALOGSERVER) <<
"Invalid map entries in networks section, failed initial check";
193 for (
int j=map0; j<=map1; ++j)
201 yCError(VIRTUALANALOGSERVER) <<
"Configure of subdevice ret false";
209 if(!config.
check(
"robotName") )
211 yCError(VIRTUALANALOGSERVER) <<
"Missing robotName, check your configuration file!";
215 if (config.
check(
"deviceId"))
217 yCError(VIRTUALANALOGSERVER) <<
"The parameter 'deviceId' has been deprecated, please use parameter 'name' instead. \n"
218 <<
"e.g. In the VFT wrapper configuration files of your robot, replace '<param name=""deviceId""> left_arm </param>' \n"
219 <<
"with '/icub/joint_vsens/left_arm:i' ";
223 std::string port_name = config.
check(
"name",
Value(
"controlboard"),
"Virtual analog wrapper port name, e.g. /icub/joint_vsens/left_arm:i").asString();
224 std::string robot_name = config.
find(
"robotName").
asString();
228 yCError(VIRTUALANALOGSERVER) <<
"Can't open port " << port_name.c_str();
247 for (
int p=0; p<polylist.
size(); ++p)
249 std::string key=polylist[p]->key;
254 if (mSubdevice.getKey() == key)
256 if (!mSubdevice.attach(polylist[p]->poly,key))
268 if (!mSubdevice.isAttached())
304 for (
int i=0; i<elems; i++)
308 yCError(VIRTUALANALOGSERVER) <<
"Invalid map entries in networks section, failed runtime check"
314 yCTrace(VIRTUALANALOGSERVER) <<
"perform_first_check() successfully completed";
322 bool sendLastValueBeforeTimeout =
false;
323 while (!Thread::isStopping())
330 sendLastValueBeforeTimeout =
false;
385 yCError(VIRTUALANALOGSERVER) <<
"Got unexpected " << pTorques->
get(0).
asInt32() <<
" message on virtualAnalogServer.";
403 if ((
lastRecv+0.080 < timeNow) && (!sendLastValueBeforeTimeout))
416 yCError(VIRTUALANALOGSERVER) <<
"Timeout!! No new value received for more than " << timeNow -
lastRecv <<
" secs.";
417 sendLastValueBeforeTimeout =
true;
yarp::sig::Vector mTorques
yarp::dev::IVirtualAnalogSensor * mpSensor
yarp::dev::PolyDriver * mpDevice
bool configure(int map0, int map1, const std::string &key)
bool attach(yarp::dev::PolyDriver *driver, const std::string &key)
std::vector< AnalogSubDevice > mSubdevices
std::vector< int > mChan2Board
bool close() override
Close the DeviceDriver.
std::vector< int > mChan2BAddr
bool attachAll(const yarp::dev::PolyDriverList &p) override
Attach to a list of objects.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool detachAll() override
Detach the object (you must have first called attach).
void run() override
Main body of the new thread.
yarp::os::BufferedPort< yarp::os::Bottle > mPortInputTorques
bool perform_first_check(int elems)
bool view(T *&x)
Get an interface to the device driver.
A container for a device driver.
bool isValid() const
Check if device is valid.
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
T * read(bool shouldWait=true) override
Read an available object from the port.
virtual bool configure(Searchable &config)
Change online parameters.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual Bottle * asList() const
Get list value.
virtual std::string asString() const
Get string value.
void resize(size_t size) override
Resize the vector.
#define yCError(component,...)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.