These are chat archives for machinekit/machinekit

26th
May 2016
zhivko
@zhivko
May 26 2016 10:22
I checked interpolator and tried to get help from @luminize, but still couldn't see a way how to add pin in nanopb terms.

I want to do similar like:

    pin = container.add_pin();
    pin->set_type(pb::ValueType::HAL_S32);
    pin->set_name("foo.1.bar");
    pin->set_hals32(4711);

but with nanopb
in message.npb.h
I do not see that typedef struct _pb_Container {
contains pins definition...
I am trying this:

    pb_Pin pin;

    pb_Container container;
    container.type = pb_ContainerType_MT_HALUPDATE;
    container.serial = 56789;
    container.rsvp = pb_ReplyType_NONE;
    container.pins.pin = pin;

But of course I get:
C+ app/application.cpp app/application.cpp: In function 'void reportEncoderPosition()': app/application.cpp:214:12: error: 'pb_Container' has no member named 'pins' container.pins.pin = pin;
Do you have any idea how can I aproach setting pin definition with nanopb Container ?

Bas de Bruijn
@luminize
May 26 2016 11:57
@zhivko I'm by no means an expert, but I searched for } pb_Container in my machinekit build directory and I got this result from include/machinetalk/generated/message.npb.h:
/* Enum definitions */
/* Struct definitions */
typedef struct _pb_Container {
    pb_ContainerType type;
    bool has_tsc;
    int64_t tsc;
    bool has_motcmd;
    pb_MotionCommand motcmd;
    bool has_motstat;
    pb_MotionStatus motstat;
    bool has_rtapi_message;
    pb_RTAPI_Message rtapi_message;
    bool has_ticket_update;
    pb_TicketUpdate ticket_update;
    bool has_tv_sec;
    int32_t tv_sec;
    bool has_tv_nsec;
    int32_t tv_nsec;
    pb_callback_t topic;
    bool has_reply_required;
    bool reply_required;
    pb_callback_t interp_name;
    bool has_rsvp;
    int32_t rsvp;
    bool has_in_reply_to;
    pb_ContainerType in_reply_to;
    bool has_rcs_status;
    pb_RCS_STATUS rcs_status;
    bool has_status;
    pb_StatusType status;
    bool has_serial;
    int32_t serial;
    bool has_reply_serial;
    int32_t reply_serial;
    bool has_ticket;
    int32_t ticket;
    bool has_reply_ticket;
    int32_t reply_ticket;
    bool has_sequence;
    int32_t sequence;
    bool has_credit;
    int32_t credit;
    bool has_line_number;
    int32_t line_number;
    pb_callback_t note;
    bool has_retcode;
    int32_t retcode;
    bool has_trace;
    bool trace;
    bool has_instance;
    int32_t instance;
    bool has_traj_set_g5x;
    pb_Emc_Traj_Set_G5x traj_set_g5x;
    bool has_traj_set_g92;
    pb_Emc_Traj_Set_G92 traj_set_g92;
    bool has_traj_set_rotation;
    pb_Emc_Traj_Set_Rotation traj_set_rotation;
    bool has_traj_linear_move;
    pb_Emc_Traj_Linear_Move traj_linear_move;
    bool has_traj_probe;
    pb_Emc_Traj_Probe traj_probe;
    bool has_traj_circular_move;
    pb_Emc_Traj_Circular_Move traj_circular_move;
    bool has_traj_rigid_tap;
    pb_Emc_Traj_Rigid_Tap traj_rigid_tap;
    bool has_traj_set_term_cond;
    pb_Emc_Traj_Set_Term_Cond traj_set_term_cond;
    bool has_traj_set_spindlesync;
    pb_Emc_Traj_Set_Spindlesync traj_set_spindlesync;
    bool has_traj_delay;
    pb_Emc_Traj_Delay traj_delay;
    bool has_spindle_on;
    pb_Emc_Spindle_On spindle_on;
    bool has_spindle_speed;
    pb_Emc_Spindle_Speed spindle_speed;
    bool has_spindle_orient;
    pb_Emc_Spindle_Orient spindle_orient;
    bool has_spindle_wait_orient_complete;
    pb_Emc_Spindle_Wait_Orient_Complete spindle_wait_orient_complete;
    bool has_tool_set_offet;
    pb_Emc_Tool_Set_Offset tool_set_offet;
    bool has_traj_set_offset;
    pb_Emc_Traj_Set_Offset traj_set_offset;
    bool has_tool_prepare;
    pb_Emc_Tool_Prepare tool_prepare;
    bool has_tool_set_number;
    pb_Emc_Tool_Set_Number tool_set_number;
    bool has_traj_set_fo_enable;
    pb_Emc_Traj_Set_Fo_Enable traj_set_fo_enable;
    bool has_traj_set_so_enable;
    pb_Emc_Traj_Set_So_Enable traj_set_so_enable;
    bool has_traj_set_fh_enable;
    pb_Emc_Traj_Set_Fh_Enable traj_set_fh_enable;
    bool has_motion_adaptive;
    pb_Emc_Motion_Adaptive motion_adaptive;
    bool has_operator_display;
    pb_Emc_Operator_Display operator_display;
    bool has_operator_text;
    pb_Emc_Operator_Text operator_text;
    bool has_operator_error;
    pb_Emc_Operator_Error operator_error;
    bool has_motion_set_dout;
    pb_Emc_Motion_Set_Dout motion_set_dout;
    bool has_motion_set_aout;
    pb_Emc_Motion_Set_Aout motion_set_aout;
    bool has_aux_input_wait;
    pb_Emc_Aux_Input_Wait aux_input_wait;
    bool has_exec_plugin_call;
    pb_Emc_Exec_Plugin_Ca1l exec_plugin_call;
    bool has_io_plugin_call;
    pb_Emc_Io_Plugin_Call io_plugin_call;
} pb_Container;
i don't see a member called pins
Michael Haberler
@mhaberler
May 26 2016 12:00
@zhivko - Container is the toplevel Container used in most messages; in the case of the interpolator I used ros.proto as toplevel messages
Michael Haberler
@mhaberler
May 26 2016 12:05
@zhivko - can you describe what you are trying to achieve? (I dont quite see it)
zhivko
@zhivko
May 26 2016 14:03
Hi. I am trying to updated hal pin, from reading of magnetic encoder position
I have esp8266, with linear magnet encoder, that I need to report position through machinetalk mechanism
Michael Haberler
@mhaberler
May 26 2016 14:05
what platform is that encoder on?
zhivko
@zhivko
May 26 2016 14:05
encoder is conected to esp8266 uC
I use Sming framework for esp8266 programming
Michael Haberler
@mhaberler
May 26 2016 14:06
can you share a link to your code? I do not know this platform - any os? bare metal?
It is SmingRTOS platform
Michael Haberler
@mhaberler
May 26 2016 14:08
is zeromq available?
zhivko
@zhivko
May 26 2016 14:08
@luminize @strahlex code is for normal protobuf - not for nanopb
I would need to find zeromq for microcontroller platform - but arduino code is easily portable to SmingRTOS framework
so if zeroMQ exists for arduino - I could port that
For video of magnetic encoder in operation see ilustrative video:
https://goo.gl/photos/Yj9saag8f2actpom7
Michael Haberler
@mhaberler
May 26 2016 14:11
so it is not, then I assume you can run tcp connections?
zhivko
@zhivko
May 26 2016 14:11
yes
hmmm how can I mark lines on github ?
Michael Haberler
@mhaberler
May 26 2016 14:12
click on line number column
Jakob Flierl
@koppi
May 26 2016 14:12
@zhivko click on the line number column on the left side, shift + click to mark a section
Michael Haberler
@mhaberler
May 26 2016 14:12
then shift-second line number
ha
OK here it is
Michael Haberler
@mhaberler
May 26 2016 14:13
so you are using websockets ?
zhivko
@zhivko
May 26 2016 14:13
You will see I tried to copy example from normal protobuf, to report hal pin value
yes
websocket are supported on SmingRtos
Michael Haberler
@mhaberler
May 26 2016 14:13
aha, that was new
zhivko
@zhivko
May 26 2016 14:14
We have WebsocketClient now... few months it is there in SmingRTOS
Michael Haberler
@mhaberler
May 26 2016 14:14
and where do you connect to, webtalk?
in that case you dont send protobuf, you send JSON, and webtalk does the protobuf/JSON conversion
zhivko
@zhivko
May 26 2016 14:14
this is tricky part - I assume python script on BBB could handle this
Like it handled protobuf from my java client
what it is called... I can check...
Michael Haberler
@mhaberler
May 26 2016 14:15
do you understand what webtalk does?
zhivko
@zhivko
May 26 2016 14:15
it is python wrapper - mkwrapper.py I think it is
Michael Haberler
@mhaberler
May 26 2016 14:15
what for
this is not for that use case
what you want to try is the following:
zhivko
@zhivko
May 26 2016 14:16
I thought I could use it for hal pin update
isn't it used for ?
Michael Haberler
@mhaberler
May 26 2016 14:17
mkwrapper is the interface to the linuxcnc module, not to HAL
that does not help you here
zhivko
@zhivko
May 26 2016 14:17
when you say webtalk you ssume machinetalk I guess ?
Michael Haberler
@mhaberler
May 26 2016 14:17
I am talking of src/machinetalk/webtalk
zhivko
@zhivko
May 26 2016 14:17
OK
So how can I then realize this scenario ?
I want to report actual axis position with this encoder - back to PIN...
Michael Haberler
@mhaberler
May 26 2016 14:18
sure
zhivko
@zhivko
May 26 2016 14:19
so do you see a way to do that ?
I thought I could use nanopb and websocket client to do that? - or should I use another approach ?
Michael Haberler
@mhaberler
May 26 2016 14:20
yes
but the idea was to enable basic JSON/websockets interoperability with webtalk
Michael Haberler
@mhaberler
May 26 2016 14:21
webtalk can automatically translate JSON to protobuf and back, so on the client you would NOT use protobuf
"to see the websockets/JSON proxy in action:"
zhivko
@zhivko
May 26 2016 14:24
So this is websocket server that runs on machine where machinekit with hal lives ?
Michael Haberler
@mhaberler
May 26 2016 14:24
yes
zhivko
@zhivko
May 26 2016 14:25
And I need to create JSON package on client and send that to this websocket server
Michael Haberler
@mhaberler
May 26 2016 14:25
it might need some love to work for you but I can help if you get stuck
zhivko
@zhivko
May 26 2016 14:25
ok nice to hear that ...
So the server side is solved I think...
So now, I need to create hal pin update JSON on client.
is there sample for that ?
so the client of sample is: gtk+ application ?
Michael Haberler
@mhaberler
May 26 2016 14:27
no
zhivko
@zhivko
May 26 2016 14:27
Where is source code of this gtk+ app ?
Michael Haberler
@mhaberler
May 26 2016 14:27
forget the gtk app, you are talking of gladevcp and that is zeromq/protobuf
this is a remote component in a browser
served by webtalk
Jakob Flierl
@koppi
May 26 2016 14:29

@mhaberler to clarify a bit, what @zhivko want's to achieve.

I have been in contact with @zhivko for the last 7 days, and know a bit more about his project: – He is setting up a pipe cutter with Machinekit, see https://github.com/zhivko/PipeCutter#pipecutter .

He has a magnetic linear position sensor that is connected to an ESP8266 via SPI. The ESP8266 should send the position data of the linear sensor to the Machinekit instance running on his BeagleBone Machinekit instance.

The code at https://github.com/zhivko/SmingRTOS is for the ESP8266, what he needs is a hal remote component on the ESP8266. – @zhivko do I understand your goal correctly?

zhivko
@zhivko
May 26 2016 14:29

OK, so I need to port:

<script src="/js/haldefs.js"></script>

<script src="/js/haltalk.js"></script>
to cpp on esp8266 to get this json

Michael Haberler
@mhaberler
May 26 2016 14:30
ah
right
zhivko
@zhivko
May 26 2016 14:31
@koppi thanks, actually it is not SPI, but ordinary signals, that triggers interrupt on esp8266 - but thank you very much for better explaining machinekit related stuff.
Michael Haberler
@mhaberler
May 26 2016 14:31
well that is a lot of effort for an SPI-connected sensor
or some other signal
zhivko
@zhivko
May 26 2016 14:32
you see one needs to reach a certain level of knowledge to be able to correctly ask question ;)
Michael Haberler
@mhaberler
May 26 2016 14:33
I have no idea about this embedded platform, never heard of it; but you might be quicker off with a straight TCP connection and a demon on the mk platform which talks to HAL
haltalk assumes zeroMQ as a transport stack
alternatively you could do this:
zhivko
@zhivko
May 26 2016 14:34
so ordinary TCP webserver listener on BBB and then webserver client on esp8266 ?
Michael Haberler
@mhaberler
May 26 2016 14:35
note I said TCP not "webserver"
zhivko
@zhivko
May 26 2016 14:35
ok this is even thinner than.
Michael Haberler
@mhaberler
May 26 2016 14:35
let me find this minimal zeromq code..
zhivko
@zhivko
May 26 2016 14:35
OK...
but ... than actually also zeromq would be needed on client I think ?
Michael Haberler
@mhaberler
May 26 2016 14:36
this might actually work directly with haltalk: https://github.com/zeromq/libzmtp
that is pretty minimal
and then you can use nanopb to en/decode the messages
this would get you around the extra hoop using websockets and json and webtalk on the host side
in fact that would be an interesting example to integrate
I suggest to enquire on the zeromq list about the status of this package - but there are recent commits so it looks active
Jakob Flierl
@koppi
May 26 2016 14:38
@mhaberler a minimal Arduino Hal remote component demo with nanopb and libzmtp would be a nice addition to the mk docs.
Michael Haberler
@mhaberler
May 26 2016 14:38
yes, definitely
that was one of the scenarios I had in mind when integrating nanopb
zhivko
@zhivko
May 26 2016 14:40
OK so zeromq client and zeromq server .... but still my question on container and pins... from the begining...
because first I need to build contatiner and than move it from client to server over nanopb zeromq infrastructure
Michael Haberler
@mhaberler
May 26 2016 14:40
so what was the problem exactly, how to seralize/deserialize using naopb?
zhivko
@zhivko
May 26 2016 14:41
no - how to build container with definitions to the pins
Michael Haberler
@mhaberler
May 26 2016 14:41
sorry no way. I have my hands full
I see
hold on
Jakob Flierl
@koppi
May 26 2016 14:42
This works with google protobuf, but not with nanopb:
    pb::Pin *pin;
    pb::Value *value;
    // type-tag the container:
    container.set_type(pb::ContainerType::MT_HALUPDATE);
    container.set_serial(56789);
    container.set_rsvp(pb::ReplyType::NONE);
    // add repeated submessage(s)
    pin = container.add_pin();
    pin->set_type(pb::ValueType::HAL_S32);
    pin->set_name("foo.1.bar");
    pin->set_hals32(4711);
zhivko
@zhivko
May 26 2016 14:42
See to return to my previous question - I tried to use protobuf example to do this... but was not succesfull - nanopb container simply doesnt support pins
https://github.com/zhivko/SmingRTOS/blob/namespace_aware/samples/StepperDM542/app/application.cpp#L213-L241
Michael Haberler
@mhaberler
May 26 2016 14:43
I think that's not correct to instantiate a submessage in nanopb
let me read the structs
zhivko
@zhivko
May 26 2016 14:44
sorry guys - need to leave now - need to pickup junior... I will follow your messages....
Michael Haberler
@mhaberler
May 26 2016 14:45
ok to summarize: your problem is to create haltalk messages in nanop then
well that is solvable
Jakob Flierl
@koppi
May 26 2016 14:50
@mhaberler the reason, @zhivko wants to use nanopb is, because there was a namespace collision between the SmingRTOS source code and the Google Protobuf library.
Michael Haberler
@mhaberler
May 26 2016 14:52
and that is not resolvable?

anyway - to make this work with nanopb, we first need to change the Container proto definition so pin and signal are emitted for nanopb, right now they are not:

    repeated Pin         pin       = 2    [(nanopb).type = FT_IGNORE];  // high frequency - use single byte tag
    repeated Signal      signal    = 3    [(nanopb).type = FT_IGNORE];  // high frequency - use single byte tag

the reason for that was that repeated objects either need a callback to decode/encode or a fixed max size, in which case they are encoded as an array of structs
I tried to make the nanopb C structs not grow too large which is why they are FT_IGNORE'd

Michael Haberler
@mhaberler
May 26 2016 14:58
so to make those usable for haltalk the nanopb option needs to be changed to [(nanopb).max_count = 10]; or so giving a max count of 10pins per message
zhivko
@zhivko
May 26 2016 14:59
Where can I made this change?
Is there conf file for nanopb generration?
Michael Haberler
@mhaberler
May 26 2016 15:02
yes exactly
so changing the proto to
    repeated Component   comp      = 100  [(nanopb).max_count = 20]; //  [(nanopb).type = FT_IGNORE];
    repeated Pin         pin       = 2   [(nanopb).max_count = 20]; //  [(nanopb).type = FT_IGNORE];  // high frequency - use single byte tag
    repeated Signal      signal    = 3  [(nanopb).max_count = 20]; //   [(nanopb).type = FT_IGNORE];  // high frequency - use single byte tag
gives this nanopb header:
typedef struct _pb_Container {
    pb_ContainerType type;
    pb_size_t pin_count;
    pb_Pin pin[20];
    pb_size_t signal_count;
    pb_Signal signal[20];
....
    pb_size_t comp_count;
    pb_Component comp[20];
so there they are
zhivko
@zhivko
May 26 2016 15:05
Ok nice i will try this.
Michael Haberler
@mhaberler
May 26 2016 15:05
that Container options should be reworked I guess - not much point in suppressing the HAL types
I think Container, Pin, Comp should be enough for an rcomp, not sure
haltalk will send a full dump of the HAL objects with a DESCRIBE message - but any object ignored in the proto naturally cant be decoded
btw if you do a PR with this proto change it should go into https://github.com/machinekit/machinetalk-protobuf - this is separate from MK for licensing reasons (creates a license firewall)
post PR you need to do the subtree update and prepare a PR for mk/mk
but that is later, for now hack it in the mk/mk repo
there is one aspect still needing adressing.. haltalk port numbers
Michael Haberler
@mhaberler
May 26 2016 15:10
normally the resolution to find a zeroMQ endpoint works through mDNS and ephemeral port numbers, but you can hardwire the port numbers in machinekit.ini - drop me a line when you get stuck there
I am assuming you dont have a decent mDNS resolver on that platform and it was very tricky to get going with the Avahi C API
if you do that - great, but I dont think that is worth the effort in that case
actually it'd be nice to have a C rcomp using zmtp and nanopb - I mean linux - just to show how it works and it might be easier to get working / debug
then move the result to embedded
(and it would give me a chance to test+help - I cannot help on your target platform but certainly on linux)
Michael Haberler
@mhaberler
May 26 2016 15:16
I think I have bad news regarding zmtp: it seems to support dealer sockets only, but not XSUB/XPUB
yes, that seems to be the case: zeromq/libzmtp#40
that sucks - meaning you cant use it for haltalk, this requires XSUB on the rcomp client
what was the namespace issue with zeroMQ C++?
I mean czmq IS C..
there is another zeromq embedded stack by some Belgian company, open source but I never tried it
Jakob Flierl
@koppi
May 26 2016 15:21
pins_arduino.h define PB 2 contradicts with app/google/protobuf/message.h:845:19: note: in expansion of macro 'PB' template<typename PB>
Michael Haberler
@mhaberler
May 26 2016 15:22
write a replacement header?
Jakob Flierl
@koppi
May 26 2016 15:27
I guess we just will have to wait until @zhivko has figured out a way to make this work either with nanopb or google protobuf, progress: see: https://github.com/zhivko/SmingRTOS/commits/namespace_aware
Michael Haberler
@mhaberler
May 26 2016 15:28
google C++ API plus czmq are way easier to use than this low-level yadayada
Michael Haberler
@mhaberler
May 26 2016 15:35
well if that PB thing is the only issue, then I'd suggest to write a C shim around it to decouple namespaces and be done with it
zhivko
@zhivko
May 26 2016 15:39
Clash was of google protobuf library and sming rtos
Pb from gooogle as protobuf and pb like portb of arduino part of sming
Michael Haberler
@mhaberler
May 26 2016 16:02
well that should be solvable with a shim ?
zhivko
@zhivko
May 26 2016 16:23
Shim like what? Sorry i am not familiar with that term