|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
26 "yarp.carrier.priority",
57 bool result = group->acceptIncomingData(reader,
this);
66 group = getPeers().add(portName,
this);
67 if (!group)
return false;
72 timeConstant = fabs(options.
check(
"tc",
Value(1.0)).asFloat64());
73 timeResting = fabs(options.
check(
"tr",
Value(0.0)).asFloat64());
84 isVirtual = options.
check(
"virtual");
86 #ifdef WITH_PRIORITY_DEBUG
87 if(options.
check(
"debug"))
91 std::snprintf(dummy, 1024,
"\n%s:\n", sourceName.c_str());
93 std::snprintf(dummy, 1024,
" stimulation: %.2f\n", stimulation);
95 std::snprintf(dummy, 1024,
" bias: %.2f\n", bias);
97 std::snprintf(dummy, 1024,
" tc: %.2fs\n", timeConstant);
99 std::snprintf(dummy, 1024,
" tr: %.2fs\n", timeResting);
101 std::snprintf(dummy, 1024,
" ex: ");
103 for(
size_t i=0; i<excitation.size(); i++)
105 Value v = excitation.get(i);
109 std::snprintf(dummy, 1024,
"(%s, %.2f) ",
117 std::snprintf(dummy, 1024,
" virtual: %s\n",
118 (isVirtual)?
"yes":
"no");
120 double rate = options.
check(
"rate",
Value(10)).asInt32() / 1000.0;
121 std::snprintf(dummy, 1024,
" db.rate: %fs\n", rate);
123 yCInfo(PRIORITYCARRIER,
"%s", msg.c_str());
125 debugger.setPeriod(rate);
158 double dt =
t - timeArrival;
162 && (dt >= fabs(timeConstant))
164 temporalStimulation = -temporalStimulation;
166 double actualStimulation;
167 if(!isResting(temporalStimulation))
171 if(dt > fabs(timeConstant))
172 actualStimulation = 0;
174 actualStimulation = temporalStimulation *
175 (1.0 - exp((dt-timeConstant)/timeConstant*5.0) + exp(-5.0));
180 if(temporalStimulation > 0)
181 actualStimulation = temporalStimulation;
184 dt -= fabs(timeConstant);
187 if(dt > fabs(timeResting))
188 actualStimulation = 0;
190 actualStimulation = temporalStimulation *
191 (1.0 - exp((dt-timeResting)/timeResting*5.0) + exp(-5.0));
195 if(actualStimulation <= 0)
198 return actualStimulation;
208 for (
auto& it : group->peerSet)
228 double I = E * getActualStimulation(
t);
229 return ((I<0) ? 0 : I);
240 int nConnections = 0;
241 for(
auto it=peerSet.begin(); it!=peerSet.end(); it++)
245 X.resize(nConnections, 1);
246 B.resize(nConnections, 1);
247 Y.resize(nConnections, 1);
248 InvA.resize(nConnections, nConnections);
252 for(
auto& rowItr : peerSet)
258 B(row,0) = peer->
bias * xi;
262 for(
auto& it : peerSet)
281 yCTrace(PRIORITYCARRIER,
"A:\n %s", InvA.toString(1).c_str());
287 yCError(PRIORITYCARRIER,
"Inconsistent regulation! non-invertible weight matrix");
295 yCTrace(PRIORITYCARRIER,
"X:\n %s", X.toString(1).c_str());
296 yCTrace(PRIORITYCARRIER,
"B:\n %s", B.toString(1).c_str());
297 yCTrace(PRIORITYCARRIER,
"Y:\n %s", Y.toString(1).c_str());
311 if(!recalculate(tNow))
316 double maxStimuli = 0.0;
317 for(
auto& it : peerSet)
320 double output = Y(row,0) * X(row,0);
325 if(output > maxStimuli)
333 accept = (maxPeer == source);
348 #ifdef WITH_PRIORITY_DEBUG
383 #endif //WITH_PRIORITY_DEBUG
A simple collection of objects that can be described and transmitted in a portable way.
void resize(size_t size) override
Resize the vector.
size_type size() const
Gets the number of elements in the bottle.
bool threadInit() override
Initialization method.
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
#define YARP_LOG_COMPONENT(name,...)
bool recalculate(double t)
Class PriorityGroup.
virtual bool acceptIncomingData(yarp::os::ConnectionReader &reader, PriorityCarrier *source)
yarp::sig::Matrix luinv(const yarp::sig::Matrix &in)
Invert a square matrix using LU-decomposition (defined in Math.h).
bool isRunning() const
Returns true when the thread is started, false otherwise.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
bool configure(yarp::os::ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
yarp::os::BufferedPort< yarp::sig::Vector > debugPort
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Allow priority-based message selection.
~PriorityDebugThread() override
static LogType minimumPrintLevel()
Get current minimum print level.
bool acceptIncomingData(yarp::os::ConnectionReader &reader) override
Determine whether incoming data should be accepted.
virtual std::string asString() const
Get string value.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
An abstraction for a periodic thread.
double det(const yarp::sig::Matrix &in)
Computes the determinant of a matrix (defined in Math.h).
virtual bool isList() const
Checks if value is a list.
#define yCAssert(component, x)
An interface for reading from a network connection.
PriorityDebugThread(PriorityCarrier *carrier)
Class PriorityDebugThread.
The basic state of a connection - route, streams in use, etc.
#define yCError(component,...)
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
double getActualInput(double t)
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
yarp::os::Bottle excitation
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
double getActualStimulation(double t)
void threadRelease() override
Release method.
void close() override
Stop port activity.
const std::string & getToName() const
Get the destination of the route.
virtual Bottle * asList() const
Get list value.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
static LogCallback printCallback()
Get current print callback.
std::string debugPortName
#define yCTrace(component,...)
PriorityCarrier * pcarrier
void run() override
Loop function.
A single value (typically within a Bottle).
const std::string & getFromName() const
Get the source of the route.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
A class for storing options and configuration information.