Skip to content

Commit

Permalink
Merge branch 'yarp-3.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
robotology-bot committed Dec 3, 2024
2 parents 7958a35 + 9565df2 commit 8be475c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 23 deletions.
19 changes: 19 additions & 0 deletions doc/release/yarp_3_10/000_yarp_3_10.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,22 @@ YARP <yarp-3.10> Release Notes
A (partial) list of bug fixed and issues resolved in this release can be found
[here](https://github.com/robotology/yarp/issues?q=label%3A%22Fixed+in%3A+YARP+yarp-3.10%22).

Fixes
-----

### GUIs

#### `yarpmotorgui`

* the default `number_of_decimals` in the slider widget has been changed from 0 to 2

### Devices

* Fixed missing encoder timestamp in `fakeMotionControl`

### Libraries

#### `libYARP_companion`

* the command `yarp read ... /port envelope` now displays the envelope inline with the data
the command `yarp read ... /port envelope2` now displays the envelope and the data on two different lines
10 changes: 6 additions & 4 deletions src/devices/fake/fakeMotionControl/FakeMotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void FakeMotionControl::run()
{
std::lock_guard lock(_mutex);

_cycleTimestamp = yarp::os::Time::now();

for (int i=0;i <_njoints ;i++)
{
if (_controlModes[i] == VOCAB_CM_VELOCITY)
Expand Down Expand Up @@ -1694,7 +1696,7 @@ bool FakeMotionControl::getEncodersTimedRaw(double *encs, double *stamps)
bool ret = getEncodersRaw(encs);
_mutex.lock();
for (int i = 0; i < _njoints; i++) {
stamps[i] = _encodersStamp[i];
stamps[i] = _encodersStamp[i] = _cycleTimestamp;
}
_mutex.unlock();
return ret;
Expand All @@ -1704,7 +1706,7 @@ bool FakeMotionControl::getEncoderTimedRaw(int j, double *encs, double *stamp)
{
bool ret = getEncoderRaw(j, encs);
_mutex.lock();
*stamp = _encodersStamp[j];
*stamp = _encodersStamp[j] = _cycleTimestamp;
_mutex.unlock();

return ret;
Expand Down Expand Up @@ -1802,7 +1804,7 @@ bool FakeMotionControl::getMotorEncodersTimedRaw(double *encs, double *stamps)
bool ret = getMotorEncodersRaw(encs);
_mutex.lock();
for (int i = 0; i < _njoints; i++) {
stamps[i] = _encodersStamp[i];
stamps[i] = _encodersStamp[i] = _cycleTimestamp;
}
_mutex.unlock();

Expand All @@ -1813,7 +1815,7 @@ bool FakeMotionControl::getMotorEncoderTimedRaw(int m, double *encs, double *sta
{
bool ret = getMotorEncoderRaw(m, encs);
_mutex.lock();
*stamp = _encodersStamp[m];
*stamp = _encodersStamp[m] = _cycleTimestamp;
_mutex.unlock();

return ret;
Expand Down
1 change: 1 addition & 0 deletions src/devices/fake/fakeMotionControl/FakeMotionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class FakeMotionControl :
};

std::recursive_mutex _mutex;
double _cycleTimestamp;
int _njoints;
int *_axisMap; /** axis remapping lookup-table */
double *_angleToEncoder; /** angle to iCubDegrees conversion factors */
Expand Down
67 changes: 55 additions & 12 deletions src/libYARP_companion/src/yarp/companion/impl/BottleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <yarp/os/Semaphore.h>
#include <yarp/os/impl/BottleImpl.h>

#include <sstream>
#include <iomanip>

using yarp::os::Bottle;
using yarp::os::Contact;
using yarp::os::ConnectionReader;
Expand All @@ -36,7 +39,7 @@ class BottleReader :
private:
yarp::os::Semaphore done;
bool raw;
bool env;
Companion::showEnvelopeEnum eShowEnvelope;
std::string::size_type trim;
bool justOnce;
Contact address;
Expand All @@ -45,15 +48,15 @@ class BottleReader :

BottleReader() : done(0) {
raw = false;
env = false;
eShowEnvelope = Companion::showEnvelopeEnum::do_not_show;
trim = std::string::npos;
justOnce = false;
core.setReader(*this);
core.setReadOnly();
}

void open(const char *name, bool showEnvelope, bool _justonce, int trim_at = -1) {
env = showEnvelope;
void open(const char *name, Companion::showEnvelopeEnum _showEnvelope, bool _justonce, int trim_at = -1) {
eShowEnvelope = _showEnvelope;
justOnce = _justonce;
trim = (trim_at > 0 ? static_cast<std::string::size_type>(trim_at) : std::string::npos);
if (core.open(name)) {
Expand All @@ -70,14 +73,28 @@ class BottleReader :
Companion::setActivePort(nullptr);
}

void showEnvelope() {
if (env) {
std::string showEnvelope() {
if (eShowEnvelope != Companion::showEnvelopeEnum::do_not_show) {
Bottle envelope;
core.getEnvelope(envelope);
if (envelope.size()>0) {
yCInfo(COMPANION, "%s ", envelope.toString().c_str());
if (envelope.size()>0)
{
//this check is bad way to test if the envelope is a actually a timestamp (yarp::os::Stamp)
if (envelope.size() == 2 && envelope.get(0).isInt32() && envelope.get(1).isFloat64())
{
std::ostringstream stream;
stream << std::fixed << std::setprecision(4) << envelope.get(1).asFloat64();
std::string formattedValue = stream.str();
return envelope.get(0).toString() + " " + formattedValue;
}
//or just a generic bottle
else
{
return envelope.toString();
}
}
}
return "";
}

bool read(ConnectionReader& reader) override {
Expand All @@ -90,17 +107,43 @@ class BottleReader :
if (bot.size()==2 && bot.isInt32(0) && bot.isString(1) && !raw) {
int code = bot.get(0).asInt32();
if (code!=1) {
showEnvelope();
yCInfo(COMPANION, "%s", bot.get(1).asString().substr(0, trim).c_str());
if (eShowEnvelope == Companion::showEnvelopeEnum::do_not_show)
{
yCInfo(COMPANION, "%s", bot.get(1).asString().substr(0, trim).c_str());
}
else if (eShowEnvelope == Companion::showEnvelopeEnum::show_inline)
{
std::string envstring = showEnvelope();
yCInfo(COMPANION, "%s %s", envstring.c_str(), bot.get(1).asString().substr(0, trim).c_str());
}
else if (eShowEnvelope == Companion::showEnvelopeEnum::show_two_lines)
{
std::string envstring = showEnvelope();
yCInfo(COMPANION, "%s", envstring.c_str());
yCInfo(COMPANION, "%s", bot.get(1).asString().substr(0, trim).c_str());
}
fflush(stdout);
}
if (code==1) {
done.post();
}
} else {
// raw = true; // don't make raw mode "sticky"
showEnvelope();
yCInfo(COMPANION, "%s", bot.toString().substr(0, trim).c_str());
if (eShowEnvelope == Companion::showEnvelopeEnum::do_not_show)
{
yCInfo(COMPANION, "%s", bot.toString().substr(0, trim).c_str());
}
if (eShowEnvelope == Companion::showEnvelopeEnum::show_inline)
{
std::string envstring = showEnvelope();
yCInfo(COMPANION, "%s %s", envstring.c_str(), bot.toString().substr(0, trim).c_str());
}
else if (eShowEnvelope == Companion::showEnvelopeEnum::show_two_lines)
{
std::string envstring = showEnvelope();
yCInfo(COMPANION, "%s", envstring.c_str());
yCInfo(COMPANION, "%s", bot.toString().substr(0, trim).c_str());
}
fflush(stdout);
}
if (justOnce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using yarp::os::NetworkBase;
* @param trim number of characters of the string that should be printed
* @return 0 on success, non-zero on failure
*/
int Companion::read(const char *name, const char *src, bool showEnvelope, bool justOnce, int trim)
int Companion::read(const char *name, const char *src, Companion::showEnvelopeEnum showEnvelope, bool justOnce, int trim)
{
Companion::installHandler();
BottleReader reader;
Expand Down Expand Up @@ -58,12 +58,15 @@ int Companion::cmdRead(int argc, char *argv[])

const char *name = argv[0];
const char *src = nullptr;
bool showEnvelope = false;
showEnvelopeEnum showEnvelope = showEnvelopeEnum::do_not_show;
size_t trim = -1;
bool justOnce = false;
bool envelopeInline = true;
while (argc>1) {
if (strcmp(argv[1], "envelope")==0) {
showEnvelope = true;
if (strcmp(argv[1], "envelope") == 0) {
showEnvelope = showEnvelopeEnum::show_inline;
} else if (strcmp(argv[1], "envelope2") == 0) {
showEnvelope = showEnvelopeEnum::show_two_lines;
} else if (strcmp(argv[1], "trim") == 0) {
argc--;
argv++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int Companion::cmdReadWrite(int argc, char *argv[])

Companion::installHandler();
BottleReader reader;
reader.open(read_port_name, false, false);
reader.open(read_port_name, Companion::showEnvelopeEnum::do_not_show, false);

int ret = write(write_port_name, 1, (char**)&verbatim);

Expand Down
8 changes: 7 additions & 1 deletion src/libYARP_companion/src/yarp/companion/impl/Companion.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class YARP_companion_API Companion

int dispatch(const char *name, int argc, char *argv[]);

enum showEnvelopeEnum
{
do_not_show = 0,
show_inline = 1,
show_two_lines = 2
};

// Defined in Companion.cmdCheck.cpp
int cmdCheck(int argc, char *argv[]);
Expand Down Expand Up @@ -102,7 +108,7 @@ class YARP_companion_API Companion
int cmdPrioritySched(int argc, char *argv[]);

// Defined in Companion.cmdRead.cpp
int read(const char *name, const char *src = nullptr, bool showEnvelope = false, bool justOnce = false, int trim = -1);
int read(const char *name, const char *src = nullptr, showEnvelopeEnum showEnvelope = showEnvelopeEnum::do_not_show, bool justOnce = false, int trim = -1);
int cmdRead(int argc, char *argv[]);

// Defined in Companion.cmdReadWrite.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/yarpmotorgui/sliderWithTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SliderWithTarget : public QSlider
bool enableViewLabel = true;
bool enableViewTargetBox = true;
bool enableViewTargetValue = false;
int number_of_decimals = 0;
int number_of_decimals = 2;
bool disableClickOutOfHandle;
SliderWithTarget(QWidget * parent = 0);
~SliderWithTarget();
Expand Down

0 comments on commit 8be475c

Please sign in to comment.