Size of a data in a Port

Hi,

we are developing an application and we would like to interchange information
(in realtime) using dataports.

It's just a buffer, with a maximum size of 1500 bytes, but we don't known the
size when we create the component. We known it in the configure step.

So, I would like to ask what would be a good approach?

- create an structure of the maximum size and send it through the port?
- create a buffer (I'm not sure if std:vector fits our needs...), and allocate
it in the configure step?

The communications will be done in the same box, but between two components.

Thanks in advance,

Leo

Size of a data in a Port

Hi

For image data type i have one structure with a pointer (but you could prefer to use vector).

In my configureHook, i get the camera image properties (width, height, depth) and initialise one sample of the image (so i allocate the buffer with the exact size).

Then i call setDataSample on the image port.

So yes, i do everything at configuration time instead of pre-allocate with maximum size.

Regards

Le 05/17/2012 09:55 AM, Leopold Palomo-Avellaneda a écrit :
> Hi,
>
> we are developing an application and we would like to interchange information
> (in realtime) using dataports.
>
> It's just a buffer, with a maximum size of 1500 bytes, but we don't known the
> size when we create the component. We known it in the configure step.
>
> So, I would like to ask what would be a good approach?
>
> - create an structure of the maximum size and send it through the port?
> - create a buffer (I'm not sure if std:vector fits our needs...), and allocate
> it in the configure step?
>
> The communications will be done in the same box, but between two components.
>
> Thanks in advance,
>
> Leo
>

Size of a data in a Port

Hi,
I'm working with Leo to develop the application he said.

@ Charles:
thank you for your hint, anyway our problem is that we don't know which
type of port we have to declare while we build the component.
We know it only when we have connected to another component (that knows the
data type of the port) and it happens in the configurehook.

Our problem is:
to declare the elementary data of a port during the configurehook, and, in
my opinion, is not linked with the use of the connection policy, that using
buffer can retreive even old data.

@ Paul:

Sorry but I haven't understand how you declare you port. Which data type
are you using when you declare the type of your port in your TaskContext
class?

Best regards
Luca

Size of a data in a Port

Le 05/19/2012 04:44 PM, Luca Magnabosco a écrit :
> Hi,
> I'm working with Leo to develop the application he said.
> [...]
> @ Paul:
>
> Sorry but I haven't understand how you declare you port. Which data type
> are you using when you declare the type of your port in your TaskContext
> class?
>
For instance the data is an array (between 0 and 1500 elements) of float declared in Data.hpp for instance :
struct Data
{
float * buffer;
unsigned buffer_cnt;
};

In my TaskContext derived class i declare
RTT::OutputPort<Data> m_data_out_port;
Data m_data_sample;

In my configureHook i setup the port
m_data_sample.buffer_cnt = 1234;
m_data_sample.buffer = new float[m_data_sample.buffer_cnt];
m_data_out_port.setDataSample(m_data_sample);

In my updateHook i never change the data size
m_data_sample.buffer[0] = foo;
m_data_sample.buffer[1] = bar;
...
m_data_sample.buffer[1233] = baz;
m_data_out_port.write(m_data);

In my cleanupHook i free the ressources
delete [] m_data_sample.buffer;

Size of a data in a Port

A Dilluns, 21 de maig de 2012, Paul Chavent va escriure:
> Le 05/19/2012 04:44 PM, Luca Magnabosco a écrit :
> > Hi,
> > I'm working with Leo to develop the application he said.
> > [...]
> > @ Paul:
> >
> > Sorry but I haven't understand how you declare you port. Which data type
> > are you using when you declare the type of your port in your TaskContext
> > class?
>
> For instance the data is an array (between 0 and 1500 elements) of float
> declared in Data.hpp for instance : struct Data
> {
> float * buffer;
> unsigned buffer_cnt;
> };
>
> In my TaskContext derived class i declare
> RTT::OutputPort<Data> m_data_out_port;
> Data m_data_sample;
>
>
> In my configureHook i setup the port
> m_data_sample.buffer_cnt = 1234;
> m_data_sample.buffer = new float[m_data_sample.buffer_cnt];
> m_data_out_port.setDataSample(m_data_sample);
>
> In my updateHook i never change the data size
> m_data_sample.buffer[0] = foo;
> m_data_sample.buffer[1] = bar;
> ...
> m_data_sample.buffer[1233] = baz;
> m_data_out_port.write(m_data);
>
> In my cleanupHook i free the ressources
> delete [] m_data_sample.buffer;

Luca,

this is more or less what I have tried to explain you today. I have proposed
you encapsulate it in a class, with some get, set and operator = defined.

Leo

Size of a data in a Port

Thank you Paul,
seem to be exactly what I was looking for.
Anyway I haven't understand yet, if you add this "Data Type" using typegen
or not,
because using typegen and typing "typegen -o types myproject Data.hpp" the
system says that pointers are not permitted.
I have to use rosgen or create a Typekit?

Best regards,
Luca

Size of a data in a Port

Indeed i don't use typegen, neither rosgen, i do my own typekit.

If you need an example of how i do, you can see here : https://gitorious.org/talc/102_video/trees/master/orocos/typekit

Le 05/24/2012 01:05 PM, Luca Magnabosco a écrit :
> Thank you Paul,
> seem to be exactly what I was looking for.
> Anyway I haven't understand yet, if you add this "Data Type" using typegen
> or not,
> because using typegen and typing "typegen -o types myproject Data.hpp" the
> system says that pointers are not permitted.
> I have to use rosgen or create a Typekit?
>
> Best regards,
> Luca
>
>
>
>

Size of a data in a Port

2012/5/17 Leopold Palomo-Avellaneda <leopold [dot] palomo [..] ...>

> Hi,

> we are developing an application and we would like to interchange
> information
> (in realtime) using dataports.
>
> It's just a buffer, with a maximum size of 1500 bytes, but we don't known
> the
> size when we create the component. We known it in the configure step.
>
> So, I would like to ask what would be a good approach?
>
> - create an structure of the maximum size and send it through the port?
> - create a buffer (I'm not sure if std:vector fits our needs...), and
> allocate
> it in the configure step?
>

Hi Leo,

Buffers are part of the Connection Policy between your two components.
Then your data port is typed with an elementary data, and the buffering is
done by RTT it-self :)

See
http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-compo...

Charles.

>
> The communications will be done in the same box, but between two
> components.
>
> Thanks in advance,
>
> Leo
>
> --
> --
> Leopold Palomo-Avellaneda <leopold [dot] palomo [..] ...>
> Institut d'Organització i Control de Sistemes Industrials -IOC-
> Universitat Politècnica de Catalunya -UPC-
>
> Institute of Industrial and Control Engineering
> Technical University of Catalonia
> Avda. Diagonal 647, pl. 11
> 08028 BARCELONA (Spain)
>
> Tel. +34-934017163
> Fax. +34-934016605
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users
>