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
Allow priority-based message selection.
bool configure(yarp::os::ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
double getActualInput(double t)
bool acceptIncomingData(yarp::os::ConnectionReader &reader) override
Determine whether incoming data should be accepted.
yarp::os::Bottle excitation
double getActualStimulation(double t)
yarp::os::BufferedPort< yarp::sig::Vector > debugPort
~PriorityDebugThread() override
void threadRelease() override
Release method.
void run() override
Loop function.
PriorityCarrier * pcarrier
bool threadInit() override
Initialization method.
PriorityDebugThread(PriorityCarrier *carrier)
Class PriorityDebugThread.
std::string debugPortName
virtual bool acceptIncomingData(yarp::os::ConnectionReader &reader, PriorityCarrier *source)
bool recalculate(double t)
Class PriorityGroup.
A simple collection of objects that can be described and transmitted in a portable way.
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 write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An interface for reading from a network connection.
The basic state of a connection - route, streams in use, etc.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
static void unlock()
Call post() on a global mutual-exclusion semaphore allocated by YARP.
static void lock()
Call wait() on a global mutual-exclusion semaphore allocated by YARP.
An abstraction for a periodic thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
const std::string & getToName() const
Get the destination of the route.
const std::string & getFromName() const
Get the source of the route.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isList() const
Checks if value is a list.
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 yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
double det(const yarp::sig::Matrix &in)
Computes the determinant of a matrix (defined in Math.h).
yarp::sig::Matrix luinv(const yarp::sig::Matrix &in)
Invert a square matrix using LU-decomposition (defined in Math.h).
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.