bobvanderlinden / node-machinetalk

A client-side Node API for remotely controlling/monitoring Machinekit instances through Machinetalk
GNU Lesser General Public License v3.0
2 stars 4 forks source link

Error 404 on renderjson.js three.js and OrbitControls.js #16

Closed zhivko closed 7 years ago

zhivko commented 8 years ago

I get folowing errors in web browser, after I start node-machinetalk-example with: .../node-machinetalk-example$ node index.js

GET http://localhost:3000/components/renderjson/renderjson.js localhost/:9 GET http://localhost:3000/components/threejs/build/three.js localhost/:10 GET http://localhost:3000/components/threejs/examples/js/controls/OrbitControls.js boundingbox.js:40 Uncaught ReferenceError: THREE is not defined(anonymous function) @ boundingbox.js:40context.execCb @ require.js:1678Module.check @ require.js:878Module.enable @ require.js:1165Module.init @ require.js:783callGetModule @ require.js:1192context.completeLoad @ require.js:1571context.onScriptLoad @ require.js:1699

Seems renderjson/renderjson.js is not part of repository - is this separate nodejs module?

zhivko commented 8 years ago

Here is screenshoot from debugger tools on chromium browser: screenshot from 2015-12-15 18 39 39

bobvanderlinden commented 8 years ago

Have you ran npm install under root by any chance? npm runs bower install after installing. Bower should then install threejs and renderjson. However, bower refuses to install when ran under root :(. I've had this problem too when running things under Docker, bower silently would not install anything.

Whatever the case, you can run bower install manually:

node_modules/.bin/bower install
zhivko commented 8 years ago

No I have not run npm install under root.

Also I cannot do: node_modules/.bin/bower install since there is no .bin directory under node_modules.

Probably I should run: sudo npm install -g bower and then: bower install

before: npm install

If you think that is the right thing to do maybe you could put that into readme.md.

zhivko commented 8 years ago

this can be closed.

bobvanderlinden commented 8 years ago

Probably I should run: sudo npm install -g bower and then: bower install

before: npm install

This is what npm should be executing automatically using the postinstall script. What version of npm and node are you running? I'd like to simulate your environment before adding it to the readme. You can check the versions using:

$ node --version
v5.3.0
$ npm --version
3.5.2
zhivko commented 8 years ago

kz@klemenHp:/mnt/Extra10Gb/git/node-machinetalk-example$ node --version v0.10.25 kz@klemenHp:/mnt/Extra10Gb/git/node-machinetalk-example$ npm --version 1.4.21 kz@klemenHp:/mnt/Extra10Gb/git/node-machinetalk-example$ uname -a Linux klemenHp 3.19.0-42-generic #48-Ubuntu SMP Thu Dec 17 22:55:02 UTC 2015 i686 i686 i686 GNU/Linux

I will try to get higher version with on my Ubuntu box with: curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - sudo apt-get install -y nodejs

OK now I have: kz@klemenHp:/mnt/Extra10Gb/git/node-machinetalk-example$ node --version v5.3.0 kz@klemenHp:/mnt/Extra10Gb/git/node-machinetalk-example$ npm --version 3.3.12

Will try to rerun machinekit-example client.

zhivko commented 8 years ago

This could be related to error on BBB - I have in /var/log/syslog: But I guess I need to open another issue. Do you maybe know what component is not correctly configured?

ec 27 02:03:37 beaglebone msgd:0: ulapi:17587:user hal_xinit:239 HAL: hal_lib17587 initialization complete
Dec 27 02:03:37 beaglebone msgd:0: hal_lib:17587:user hal_xinit:246 HAL: legacy component 'halcmd17587' id=645 initialized
Dec 27 02:03:40 beaglebone avahi-daemon[532]: server.c: Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)
Dec 27 02:03:41 beaglebone avahi-daemon[532]: server.c: Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)
Dec 27 02:03:43 beaglebone avahi-daemon[532]: server.c: Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)
Dec 27 02:03:49 beaglebone avahi-daemon[532]: server.c: Packet too short or invalid while reading known answer record. (Maybe a UTF-8 problem?)

And in linuxcnc.log this line is strange: Dec 27 08:19:35 beaglebone webtalk: webtalk: talking Machinekit http on '(null)'

on '(null)' ?

Dec 27 08:19:35 beaglebone webtalk: [0.013636] NOTICE:  Compiled with OpenSSL support
Dec 27 08:19:35 beaglebone webtalk: [0.013674] NOTICE:  Using non-SSL mode
Dec 27 08:19:35 beaglebone webtalk: [0.067490] NOTICE:  Listening on port 7681
Dec 27 08:19:35 beaglebone webtalk: register_stuff: actual hostname as announced by avahi='beaglebone.local'
Dec 27 08:19:35 beaglebone webtalk: webtalk: talking Machinekit http on '(null)'
Dec 27 08:19:35 beaglebone webtalk: zeroconf: registering: 'Machinekit on beaglebone.local pid 22444'
Dec 27 08:19:35 beaglebone webtalk: webtalk: signal 15 - 'Terminated' received
Dec 27 08:19:35 beaglebone webtalk: [0.437381] NOTICE: libwebsocket_context_destroy
Dec 27 08:19:35 beaglebone webtalk: webtalk: exiting mainloop (interrupted)
Dec 27 08:19:35 beaglebone webtalk: zeroconf: unregistering 'Machinekit on beaglebone.local pid 22444'
Dec 27 08:22:52 beaglebone msgd:0: msgd:0: got signal 15 - sending SIGTERM to rtapi (pid 17190)
Dec 27 08:22:52 beaglebone msgd:0: msgd:0: Terminated - shutting down
Dec 27 08:22:52 beaglebone msgd:0: zeroconf: unregistering 'Log service on beaglebone.local pid 17183'
Dec 27 08:22:52 beaglebone msgd:0: log buffer hwm: 9% (496 msgs, 47740 bytes out of 524288)
Dec 27 08:22:52 beaglebone msgd:0: sent SIGTERM to rtapi (pid 17190)
Dec 27 08:22:52 beaglebone msgd:0: normal shutdown - global segment detached
zhivko commented 8 years ago

So I can list machines from node-machinetalk:

kz@klemenHp:~/git/node-machinetalk/examples$ node list-machines.js 
*** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
*** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
Machine 72c3f16f-59c3-4116-ba4f-709959abb157 up
Machine 72c3f16f-59c3-4116-ba4f-709959abb157 : Service log : tcp://beaglebone.local:49152
Machine 72c3f16f-59c3-4116-ba4f-709959abb157 : Service log : tcp://beaglebone.local:49152

but trying node-machinetalk-example project I get:

kz@klemenHp:~/git/node-machinetalk-example$ node index.js 
*** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
*** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>
listening on http://localhost:3000/
Browser error { [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }
Browser error { [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }

And no machines listed on httt://localhost:3000

screenshot from 2015-12-27 11 12 22

Any idea?

bobvanderlinden commented 8 years ago

Alright. This is indeed related to #17. node_mdns needs to be fixed. The fix is already available, but was not used yet as it is not in a released version of node_mdns. There isn't a 'stable' version available yet. However, the latest development version of node-machinetalk-example on Git now points to the latest development version of node-machinetalk, which points to a patched version of node_mdns. If you pull node-machinetalk-example (git pull), delete node_modules (rm -rf node_modules) and run npm install again, you should get the patched version as well, which should not give the getaddrinfo -3008 errors anymore.

zhivko commented 8 years ago

"latest development version" == bleading branch on node-machinetalk-example?

zhivko commented 8 years ago

OK - there is no error anmore but machines box is still empty :) although I have machinekit running on bbb: kz@klemenHp:~/git/node-machinetalk-example$ avahi-browse -a

bobvanderlinden commented 8 years ago

I don't see the machinetalk services being online now in that output, whereas your earlier comment ( https://github.com/bobvanderlinden/node-machinetalk/issues/17#issuecomment-167369405) did show online machinetalk services (command, error, status, preview, etc). Are you sure you're running mkwrapper in Machinekit?

On Sun, Dec 27, 2015, 23:34 zhivko notifications@github.com wrote:

OK - there is no error anmore but machines box is still empty :) although I have machinekit running on bbb: kz@klemenHp:~/git/node-machinetalk-example$ avahi-browse -a

  • wlan0 IPv6 Log service on beaglebone.local pid 3195 _machinekit._tcp local
  • wlan0 IPv4 Machinekit _machinekit._tcp local
  • wlan0 IPv4 Log service on beaglebone.local pid 3195 _machinekit._tcp local
  • wlan0 IPv6 Machinekit on beaglebone.local pid 3162 Web Site local
  • wlan0 IPv4 Machinekit on beaglebone.local pid 3162 Web Site local
  • wlan0 IPv6 klemenHp [00:22:fa:c5:c4:50] Workstation local
  • wlan0 IPv4 klemenHp [00:22:fa:c5:c4:50] Workstation local
  • wlan0 IPv6 klemenHp Remote Disk Management local
  • wlan0 IPv4 klemenHp Remote Disk Management local
  • wlan0 IPv6 beaglebone [54:4a:16:c5:d0:2a] Workstation local
  • wlan0 IPv6 beaglebone Remote Disk Management local
  • wlan0 IPv4 beaglebone [54:4a:16:c5:d0:2a] Workstation local
  • wlan0 IPv4 beaglebone Remote Disk Management local

— Reply to this email directly or view it on GitHub https://github.com/bobvanderlinden/node-machinetalk/issues/16#issuecomment-167445406 .

zhivko commented 8 years ago

Ups :) I am using

rundemo

from git/machinekit/src/machinetalk/tutorial/motorctrl

So I suppose mkwrapper is the right tool to run on BBB. Have I miss that information? It would be nice to put that in readme.MD (I mean what to run on BBB side so node-machinetalk could work).

bobvanderlinden commented 8 years ago

Ah, yes you hit the nail on the head. This wasn't documented yet and it seems there aren't any example configurations for mkwrapper in Machinekit yet. I've added instructions to the readme of node-machinetalk-example. @strahlex has a full-featured simulator example that is available here: https://github.com/strahlex/mkwrapper-sim

@strahlex, what do you think about merging mkwrapper-sim into Machinekit? Is it stable enough or would a different approach be better?

machinekoder commented 8 years ago

Since it is a copy of the sim/axis example I think adding it as sim/mkwrapper example might be suitable. Just not sure how much value it adds at this state since it will not work with the linuxcnc configuration selector.

zhivko commented 8 years ago

Great - with:

DISPLAY = mkwrapper

inside my machinekit ini file, I can finally connect to BBB with node-machinetalk-example and use it - to see what is all about. Is there a chance to load a 3d model and see gcode path? To ask for 4 axis movement is probably already too much? I would like to show something like: https://photos.google.com/u/0/share/AF1QipNjVgZFrfCcDP-1fOkU-AJGnM4dq6xbf1txdeZfzpNrJin55Nq9DZVauh3vyL5ndQ/photo/AF1QipNGFyE-yivWM7mWXy-O_gct1LBPgyneRlPYXzuN?key=emhhOHJmaEUtNlM2VUhXWVVXRmp0b2xJNzBtdzNB

Do you maybe know what is easiest way to integrate with machinetalk from JAVA application? This might be outside of scope of this issue.

machinekoder commented 8 years ago

@zhivko First start by figuring out how ZeroMQ and Protobuf works for Java: http://zeromq.org/bindings:java https://developers.google.com/protocol-buffers/docs/javatutorial?hl=en Then figure out how to use ZeroConf within Java: http://jmdns.sourceforge.net/ And once you got a simple example running you may create a code generator for Java bindings for fastest results: https://github.com/strahlex/machinetalk-gsl/blob/master/scripts/jsgen.gsl

zhivko commented 8 years ago

@strahlex for start I tried java mdns example (attached) and somehow I cannot discover machinekit "_machinekit._tcp.local." running on beaglebone black. I am using mdn implementation from following maven repo:

        <dependency>
            <groupId>javax.jmdns</groupId>
            <artifactId>jmdns</artifactId>
            <version>3.4.1</version>
        </dependency>

My sample code is here: https://github.com/zhivko/PipeCutter/blob/master/src/main/java/com/kz/pipeCutter/BBB/Discoverer.java

Is there some catch - do I maybe need to call some different bonjourServiceType instead "_machinekit._tcp.local."?

I can sucesfully get www services with same maven mdn library and bonjourServiceType = "_http._tcp.local."...

avahi-browse -a shows:

kz@klemenHp:~/git/PipeCutter$ avahi-browse -a
+   eth1 IPv6 klemenHp                                      Remote Disk Management local
+   eth1 IPv4 klemenHp                                      Remote Disk Management local
+  wlan0 IPv6 klemenHp                                      Remote Disk Management local
+  wlan0 IPv4 klemenHp                                      Remote Disk Management local
+   eth1 IPv6 klemenHp [54:4a:16:c5:d0:2c]                  Workstation          local
+   eth1 IPv4 klemenHp [54:4a:16:c5:d0:2c]                  Workstation          local
+  wlan0 IPv6 klemenHp [00:22:fa:c5:c4:50]                  Workstation          local
+  wlan0 IPv4 klemenHp [00:22:fa:c5:c4:50]                  Workstation          local
+   eth1 IPv6 beaglebone                                    Remote Disk Management local
+   eth1 IPv6 beaglebone [54:4a:16:c5:d0:20]                Workstation          local
+   eth1 IPv4 beaglebone                                    Remote Disk Management local
+   eth1 IPv4 beaglebone [54:4a:16:c5:d0:20]                Workstation          local
+  wlan0 IPv4 Deskjet 3050A J611 series [7C551F]            Internet Printer     local
+  wlan0 IPv4 Deskjet 3050A J611 series [7C551F]            PDL Printer          local
+  wlan0 IPv4 Deskjet 3050A J611 series [7C551F]            Web Site             local
+  wlan0 IPv4 Deskjet 3050A J611 series [7C551F]            _scanner._tcp        local
+  wlan0 IPv4 Deskjet 3050A J611 series [7C551F]            _http-alt._tcp       local
+   eth1 IPv6 Log service on beaglebone.local pid 5421      _machinekit._tcp     local
+   eth1 IPv4 Log service on beaglebone.local pid 5421      _machinekit._tcp     local
+   eth1 IPv4 Previewstatus service on beaglebone.local pid 5833 _machinekit._tcp     local
+   eth1 IPv4 Preview service on beaglebone.local pid 5833  _machinekit._tcp     local
+   eth1 IPv4 Command service on beaglebone.local pid 5833  _machinekit._tcp     local
+   eth1 IPv4 Error service on beaglebone.local pid 5833    _machinekit._tcp     local
+   eth1 IPv4 Status service on beaglebone.local pid 5833   _machinekit._tcp     local
+   eth1 IPv4 File service on beaglebone.local pid 5833     _machinekit._tcp     local

Best wishes for 2016 and HappyNew year!!

machinekoder commented 8 years ago

@zhivko Some libraries need the correct subtypes too for the service discovery to work. Try _status._sub._machinekit._tcp.local. You setup also indicates that you have two network interfaces present. Make sure to do the lookups on the correct one (or both).

Happy New Year!

zhivko commented 8 years ago

@bobvanderlinden very sorry for hijacking your machinekit-example issues for this purpose. If there is better place where I should put it please suggest. @strahlex Thanks for the tip. Indeed there are more interafaces and now I got to the point I can list machinekit remote services. I have connected BBB over USB, so it has 192.168.7.2 IP address. What my java program now outputs is somehow weird since instead of BBB IP it outputs (null). See my present example from full code available at: https://github.com/zhivko/PipeCutter/blob/master/src/main/java/com/kz/pipeCutter/BBB/Discoverer.java: This is my current version of java program in wich I do not get response from command service, can you suggest what are typical url's for command service that works at your side for example or give me some hint what's wrong...

        // TODO Auto-generated method stub
        Discoverer discoverer = new Discoverer();
//      /192.168.7.1
//      Added: [ServiceInfoImpl@11393876 name: 'Status service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):64306' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@32678821 name: 'Command service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):64907' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@11714816 name: 'Preview service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):49153' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@28660940 name: 'Log service on beaglebone._local pid 4714._machinekit._tcp.local.' address: '(null):49152' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@21779733 name: 'File service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):58192' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@28650770 name: 'Error service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):59611' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      Added: [ServiceInfoImpl@22366245 name: 'Previewstatus service on beaglebone._local pid 5126._machinekit._tcp.local.' address: '(null):49154' status: 'NO DNS state: probing 1 task: null', has NO data empty]
//      /192.168.1.106
//      /127.0.0.1      
        ServiceInfo command = discoverer.getCommandService();
        String commandUrl = command.getProtocol() + "://" + command.getServer() + ":" + command.getPort() + "/";
        System.out.println("command url: " + commandUrl);
        // tcp://beaglebone.local.:64907/
        Context con = ZMQ.context(1);
        Socket req = con.socket(ZMQ.REQ);
        req.connect(commandUrl);
        req.send("test");
        String result = req.recvStr();
bobvanderlinden commented 8 years ago

@zhivko No worries, it's an interesting topic for me too. It's alright with me to have the discussion here, but it might be easier for others to find if it were discussed in https://github.com/machinekit/machinekit or even https://github.com/strahlex/machinetalk-gsl.

@zhivko I could likely be wrong here, but I can imagine the address solving going wrong (as it might be resolving beaglebone._local instead of beaglebone.local).

zhivko commented 8 years ago

@bobvanderlinden I am also trying with tcp://beaglebone.local:64907/ like:

Context con = ZMQ.context(1);
        Socket req = con.socket(ZMQ.REQ);
        req.connect("tcp://beaglebone.local:64907/");
        req.send("test");
        String result = req.recvStr();

with no reply from BBB.

@bobvanderlinden Isn't your client: node-machinetalk-example using same principles of accessing service on BBB? I tried to search over your code to find this service url with no avail. Can you put it here what - form is it?

@strahlex is machinekit java protobuf available to download from some maven repo? If not is it possible to build it somehow (how?) with https://github.com/strahlex/machinetalk-gsl/blob/master/scripts/jsgen.gsl?

Is there some existing machinekit java code floating around for java - machinekit integration?

bobvanderlinden commented 8 years ago

Ah, ok. It's the same. I get the same domain+port pattern from mdns, so that's good. Which service are you accessing with tcp://beaglebone.local:64907/? status, command, halrcmd, etc? If you're accessing status you need a ZMQ.SUB socket (see http://zguide.zeromq.org/java:psenvsub). Additionally, you need to subscribe to a topic. This is a feature of ZMQ, so I'd think you can do:

Socket socket = con.socket(ZMQ.SUB);
socket.connect("tcp://beaglebone.local:64907/");
socket.subscribe("task".getBytes());
socket.subscribe("motion".getBytes());
socket.subscribe("io".getBytes());
socket.subscribe("interp".getBytes());
socket.subscribe("config".getBytes());
String content = socket.recvStr();

Note that you cannot send anything to the status service.

If you want to access the command service you need ZMQ.DEALER (see http://zguide.zeromq.org/java:rtdealer). It'll look similar to:

Socket socket = con.socket(ZMQ.DEALER);
socket.connect("tcp://beaglebone.local:64907/");
socket.send(protobufMessageBytes);

Note that you don't get anything back when communicating with the command service.

zhivko commented 8 years ago

@bobvanderlinden thank you VERY much for the tip how to use this library. The success for me would be to send some command over command service (lets say G0 command), and than observe movements via received bytes from motion service. It seems to me that I need to use command service, but for this to work I need java protobuf classes for machinetalk (so I could encode and decode messages properly).

So I tried to generate those java classes issuing:

kz@klemenHp:/mnt/Extra10Gb/git/machinetalk-protobuf$ protoc --proto_path=src --java_out=build/gen src/machinetalk/protobuf/*.proto
google/protobuf/descriptor.proto: File not found.
machinetalk/protobuf/nanopb.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
machinetalk/protobuf/nanopb.proto:75:8: "google.protobuf.FileOptions" is not defined.
machinetalk/protobuf/nanopb.proto:79:8: "google.protobuf.MessageOptions" is not defined.
machinetalk/protobuf/nanopb.proto:83:8: "google.protobuf.EnumOptions" is not defined.
machinetalk/protobuf/nanopb.proto:87:8: "google.protobuf.FieldOptions" is not defined.
machinetalk/protobuf/types.proto: Import "machinetalk/protobuf/nanopb.proto" was not found or had errors.
machinetalk/protobuf/emcclass.proto: Import "machinetalk/protobuf/nanopb.proto" was not found or had errors.
machinetalk/protobuf/motcmds.proto: Import "machinetalk/protobuf/emcclass.proto" was not found or had errors.
machinetalk/protobuf/motcmds.proto: Import "machinetalk/protobuf/nanopb.proto" was not found or had errors.
machinetalk/protobuf/motcmds.proto:115:14: "EmcPose" is not defined.
machinetalk/protobuf/motcmds.proto:116:14: "PmCartesian" is not defined.
machinetalk/protobuf/motcmds.proto:117:14: "PmCartesian" is not defined.
machinetalk/protobuf/motcmds.proto:158:14: "EmcPose" is not defined.
machinetalk/protobuf/motcmds.proto:169:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto: Import "machinetalk/protobuf/nanopb.proto" was not found or had errors.
machinetalk/protobuf/canon.proto: Import "machinetalk/protobuf/types.proto" was not found or had errors.
machinetalk/protobuf/canon.proto: Import "machinetalk/protobuf/emcclass.proto" was not found or had errors.
machinetalk/protobuf/canon.proto: Import "machinetalk/protobuf/motcmds.proto" was not found or had errors.
machinetalk/protobuf/canon.proto:30:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:31:14: "OriginIndex" is not defined.
machinetalk/protobuf/canon.proto:38:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:52:14: "MotionType" is not defined.
machinetalk/protobuf/canon.proto:53:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:65:14: "MotionType" is not defined.
machinetalk/protobuf/canon.proto:66:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:77:14: "MotionType" is not defined.
machinetalk/protobuf/canon.proto:78:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:79:14: "PmCartesian" is not defined.
machinetalk/protobuf/canon.proto:80:14: "PmCartesian" is not defined.
machinetalk/protobuf/canon.proto:92:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:102:14: "TermConditionType" is not defined.
machinetalk/protobuf/canon.proto:144:14: "CanonDirection" is not defined.
machinetalk/protobuf/canon.proto:160:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:171:14: "EmcPose" is not defined.
machinetalk/protobuf/canon.proto:266:14: "InputType" is not defined.
machinetalk/protobuf/canon.proto:267:14: "WaitType" is not defined.

So it seemed to me that I miss some google protobuf dependencies and I soft linked google protobuf src folder /home/kz/git/protobuf/src/google to /home/kz/git/machinetalk-protobuf/src/google. As soon as I got feeling I am at the end of it I got following:

kz@klemenHp:/mnt/Extra10Gb/git/machinetalk-protobuf/src$ protoc --proto_path=./ --java_out=./build/gen ./machinetalk/protobuf/*.proto[libprotobuf WARNING google/protobuf/compiler/java/java_file.cc:197] machinetalk/protobuf/preview.proto: The default outer class name, "Preview", conflicts with a type declared in the proto file and an alternative outer class name is used: "PreviewOuterClass". To avoid this warning, please use the java_outer_classname option to specify a different outer class name for the .proto file.
[libprotobuf WARNING google/protobuf/compiler/java/java_file.cc:197] machinetalk/protobuf/value.proto: The default outer class name, "Value", conflicts with a type declared in the proto file and an alternative outer class name is used: "ValueOuterClass". To avoid this warning, please use the java_outer_classname option to specify a different outer class name for the .proto file.

It seems I need to add java_outer_classname to the proto files of machinekit. Do you really think I need to do that? I guess not since that needs to be part of machinekit protobuff project... Please suggest proper way to address this and move forward...

EDIT: I just now saw that this is just a WARNING so things could just work. with:

kz@klemenHp:~/git/machinetalk-protobuf/src$ protoc --proto_path=./ --java_out=./../build/java ./machinetalk/protobuf/*.proto

I can see java classes were generated in:

/home/kz/git/machinetalk-protobuf/build/java
machinekoder commented 8 years ago

@zhivko The Machinetalk Protobuf definitions have dependencies and need to be generated in a certain order. Generating Java files should be pretty similar to generating C++ files. Do you have experience with Makefiles? It should be pretty much copying the cpp commands and renaming everything to java https://github.com/machinekit/machinetalk-protobuf/blob/master/Makefile#L138

machinekoder commented 8 years ago

@zhivko This branch might be good enough for you to try https://github.com/strahlex/machinetalk-protobuf/tree/java just run make

machinekoder commented 8 years ago

@zhivko There aren't machinetalk binding for Java at the moment. So start by making a small proof of concept example. For adding a code generator we need following Java components:

bobvanderlinden commented 8 years ago

@zhivko For testing purposes, you can try to encode a message with a supported language and use the bytes.

For instance:

var machinetalkProtobuf = require('../index.js');

// Define the message we want to encode.
var messageContainer = {
  type: machinetalkProtobuf.message.ContainerType.MT_EMC_TASK_SET_STATE,
  interp_name: 'execute',
  task_mode: machinetalkProtobuf.message.ContainerType.EMC_TASK_STATE_ESTOP
};

// Encode the message.
var encodedMessageContainer = machinetalkProtobuf.message.Container.encode(messageContainer);

// Strip off excess bytes from the resulting buffer.
var encodedBuffer = encodedMessageContainer.buffer.slice(encodedMessageContainer.offset, encodedMessageContainer.limit);

// Print the buffer.
console.log(encodedBuffer);

Results in 08 89 52 d2 01 07 65 78 65 63 75 74 65. If you send that over the command service, Machinekit should go into ESTOP state.

zhivko commented 8 years ago

@strahlex I cloned your suggested repo, but running make - doesn't give me any java files however there are javascript files and objects - I wonder if you though javascript or java - they are easily phonetically mixed but they are not same . @bobvanderlinden I tried to send char bytes and I thought I would get some response on any of: socket.subscribe("task".getBytes()); socket.subscribe("motion".getBytes()); socket.subscribe("io".getBytes()); socket.subscribe("interp".getBytes()); socket.subscribe("config".getBytes()); but I didn't get any. I havent yet checked CRAMPS hat leds to see if it changes since I know leds changes when I click estop in axis. I would check that later. @strahlex do you think java classes generated with:

protoc --proto_path=./ --java_out=./../build/java ./machinetalk/protobuf/*.proto

would not work? Do you think I need to run

protoc --proto_path=./ --java_out=./../build/java ./machinetalk/protobuf/*.proto

while in https://github.com/strahlex/machinetalk-protobuf/tree/java ?

machinekoder commented 8 years ago

@zhivko make sure to checkout the java branch git checkout origin/java

zhivko commented 8 years ago

@strahlex ah yes :) that's better. I got java classes with make now.

zhivko commented 8 years ago

@strahlex Yesterday I were struggling with machinetalk java classes. There is no setters on classes just getters, so I find this quite unusual from java point of view. Actually I don't have idea how to use those, so any examples from c++ are very welcomed (can you point me to any of them if they maybe exist). Currently I have this (https://github.com/zhivko/PipeCutter/blob/master/src/main/java/com/kz/pipeCutter/BBB/BBBCommand.java):

...
public class BBBCommand {
    ServiceListener bonjourServiceListener;
    ArrayList<ServiceInfo> services;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        byte[] buff;
        //String s="088952d2010765786563757465";
        //byte[] buff = new BigInteger(s,16).toByteArray();
        Context con = ZMQ.context(1);
        Socket socket = con.socket(ZMQ.DEALER);
        socket.connect("tcp://192.168.7.2:55236/");
        Message.Container msgContainer = Message.Container.getDefaultInstance();
        MotionCommand motionCmd = Message.Container.getDefaultInstance().getMotcmd();
        EmcStatusTask task = msgContainer.getEmcStatusTask().getDefaultInstanceForType();
        //task.getTaskMode().values() = EmcTaskModeType.EMC_TASK_MODE_AUTO;
        buff = task.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
        System.out.println(hexOutput);
        socket.send(buff);      
    }
}

I would kindly ask for idea (code snippet) how to use machinetalk from client side and another point - how it is meant to transfer gcode program over machinetalk (which classes to use and what fields to modify) before encoding message.

machinekoder commented 8 years ago

@zhivko Take a look at https://github.com/strahlex/QtQuickVcp/blob/master/src/application/qapplicationcommand.cpp#L490 and https://developers.google.com/protocol-buffers/docs/javatutorial I have never used protobuf for Java but here is an example:

Person john =
  Person.newBuilder()
    .setId(1234)
    .setName("John Doe")
    .setEmail("jdoe@example.com")
    .addPhone(
      Person.PhoneNumber.newBuilder()
        .setNumber("555-4321")
        .setType(Person.PhoneType.HOME))
    .build();

Hint from the tutorial "The message classes generated by the protocol buffer compiler are all immutable. Once a message object is constructed, it cannot be modified, just like a Java String".

zhivko commented 8 years ago

With the help of @bobvanderlinden my example now respond to PING call, but sending or resting estop is out of my reach. I dont see how to connect bits and pieces of all possible machinetalk commands i.e. for Types.ContainerType.MT_EMC_TASK_SET_STATE and to see what all possible parameters this command could have (and how to set those parameters).

here is my latest attempt:

package com.kz.pipeCutter.BBB;

import java.util.ArrayList;

import javax.jmdns.ServiceInfo;
import javax.jmdns.ServiceListener;

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

import com.google.protobuf.InvalidProtocolBufferException;

import pb.Message;
import pb.Message.Container;
import pb.Status;
import pb.Status.EmcStatusTask;
import pb.Task;
import pb.Types;

public class BBBCommand {
    ServiceListener bonjourServiceListener;
    ArrayList<ServiceInfo> services;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        byte[] buff;
        Context con = ZMQ.context(1);
        Socket socket = con.socket(ZMQ.DEALER);
        socket.connect("tcp://beaglebone.local:57668/");
        Container container = Container.newBuilder()
                .setType(Types.ContainerType.MT_PING).build();

        buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter
                .printHexBinary(buff);
        System.out.println(hexOutput);
        socket.send(buff);

        byte[] received = socket.recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        container = Container.newBuilder()
                .setType(Types.ContainerType.MT_EMC_TASK_SET_STATE).build();
        container.getAllFields().put(container.getOneofFieldDescriptor(getField(Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP.getValueDescriptor());// .getAllFields().put(Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP_VALUE,  "emc_command_params","task_state");
        buff = container.toByteArray();
        hexOutput = javax.xml.bind.DatatypeConverter
                .printHexBinary(buff);
        System.out.println(hexOutput);
        socket.send(buff);
        received = socket.recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

FIrst part of code succesfully pings machinekit on BBB, but second part does not even compile since I dont have a clew what parameters to set for Types.ContainerType.MT_EMC_TASK_SET_STATE

In https://github.com/machinekit/machinekit/blob/master/src/machinetalk/mkwrapper/mkwrapper.py is:

            elif self.rx.type == MT_EMC_TASK_SET_STATE:
                if self.rx.HasField('emc_command_params') \
                and self.rx.emc_command_params.HasField('task_state') \
                and self.rx.HasField('interp_name'):
                    if self.rx.interp_name == 'execute':
                        self.command.state(self.rx.emc_command_params.task_state)
                        if self.rx.HasField('ticket'):
                            self.wait_complete(identity, self.rx.ticket)

So probably I need to set those fields somehow...

bobvanderlinden commented 8 years ago

I presume (I haven't checked) that you can send the ESTOP command with something like:

pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters.newBuilder()
.setTaskState(Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP)
.build();
Container container = Container.newBuilder()
.setType(Types.ContainerType.MT_EMC_TASK_SET_STATE)
.setEmcCommandParams(emcCommandParameter)
.setInterpName("execute")
.build();
zhivko commented 8 years ago

Just tried your suggestion - it produced following message: 088952D2010765786563757465922603A80601 But with suggested code I don't get any reply from BBB command service so code just waits in last line of:

        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
            .newBuilder()
            .setTaskState(
                Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP)
            .build();
        Container container = Container
            .newBuilder()
            .setType(
                Types.ContainerType.MT_EMC_TASK_SET_STATE)
            .setEmcCommandParams(emcCommandParameter)
            .setInterpName("execute").build();

        buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter
            .printHexBinary(buff);
        System.out.println(hexOutput);
// prints 088952D2010765786563757465922603A80601
        socket.send(buff);
        byte[] received = socket.recv();

I tried enabling debug on BBB machinekit side with modifiying CRAMPS.ini with:

DEBUG = 0x00000007

but /var/log/linuxcnc.log stays same - nothing usefull in it to help me understand any weird circumstances why command is not executed...

machinekoder commented 8 years ago

@zhivko If you add a ticket field to your request you will get a response. If not then no response will be sent.

pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters.newBuilder()
.setTaskState(Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP)
.build();
Container container = Container.newBuilder()
.setType(Types.ContainerType.MT_EMC_TASK_SET_STATE)
.setEmcCommandParams(emcCommandParameter)
.setInterpName("execute")
.setTicket(123)
.build();
zhivko commented 8 years ago

All right! With this code:

        pb.Message.Container.Builder builder = Container
            .newBuilder();
        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
            .newBuilder().setDebugLevel(2)
            .setTaskState(
                Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP)
            .build();

        builder.setType(ContainerType.MT_EMC_TASK_SET_STATE);
        builder.setEmcCommandParams(emcCommandParameter);
        builder.setInterpName("execute");
        builder.setTicket(1);

        Container container = builder.build();

        buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter
            .printHexBinary(buff);
        System.out.println(hexOutput);
        socket.send(buff);
        byte[] received = socket.recv();
        try {
            Container contReturned = Container
                .parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

I get following in output:

088952D2010765786563757465B803019226051002A80601
type: MT_EMCCMD_EXECUTED
reply_ticket: 1

Obviously command was processed - but on CRAMPS hat, ESTOP red led is still turned on. I have following questions: 1.) how to reset this estop led? 2.) How to send gcode program to BBB 3.) Also how .newBuilder().setDebugLevel(2) should be used? Where can I see those debug messages. Should I connect to Log service? If yes on which topic I need to subscribe?

machinekoder commented 8 years ago

To reset the estop you need to set the correct task state estop reset https://github.com/machinekit/machinetalk-protobuf/blob/master/src/machinetalk/protobuf/status.proto#L118

The debug level is set using another message: https://github.com/strahlex/machinetalk-gsl/blob/master/models/application/command_protocol.xml#L54 However, I have no idea if the debug output works and where it is output. It just maps to the LinuxCNC Python bindings.

To send/receive file you will need to use the file service. The file service uses FTP best google Java FTP client and you find some examples.

After you uploaded the file you need to open it https://github.com/strahlex/machinetalk-gsl/blob/master/models/application/command_protocol.xml#L157 interp_name is 'execute'

Sorry for the complicated setup. I am working on connection the dots to make Machinekit a little bit more clear.

zhivko commented 8 years ago

Yes that was another thing I also tried before you replied:

        pb.Message.Container.Builder builder = Container.newBuilder();
        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
                .newBuilder()
                .setTaskState(Status.EmcTaskStateType.EMC_TASK_STATE_ESTOP_RESET).build();

        builder.setType(ContainerType.MT_EMC_TASK_SET_STATE);
        builder.setEmcCommandParams(emcCommandParameter);
        builder.setInterpName("execute");
        builder.setTicket(1);

        Container container = builder.build();

        byte[] buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
        System.out.println("Message: " + hexOutput);
        getSocket().send(buff);
        byte[] received = getSocket().recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

I get:

Message: 088952D2010765786563757465B80301922603A80602
type: MT_EMCCMD_EXECUTED
reply_ticket: 1

but red ESTOP led on CRAMPS is still turned on...

Ftp client will not be a problem. Today I fixed systemctl on BBB to load mkwrapper as service on startup - thanks to your script at https://github.com/strahlex/asciidoc-sandbox/blob/master/Starting-a-Machinekit-configuration-at-boot.md. Just for the record - maybe it could help somebody - here is what I have now:

sudo nano /etc/systemd/system/pipecutter.service

content:

[Unit]
Description=Starts my pipecutter Machinekit configuration
After=syslog.target network.target ssh.service avahi-daemon.service
Requires=network.target

[Service]
Type=simple
ExecStart=/usr/bin/python /usr/bin/mkwrapper -ini /home/machinekit/machinekit/configs/ARM.BeagleBone.CRAMPS/CRAMPS.ini
User=machinekit
LimitMEMLOCK=33554432

[Install]
WantedBy=multi-user.target

It's good to have a responsive community, if all documentation is not in place... Machinekit looks quite promissing and integration to different clients would make it even more popular... So I think uploading gcode file, starting a gcode file, jogging, are just few basic scenarios that should be somehow covered in documentation to make people use it more.

bobvanderlinden commented 8 years ago

It seems for CRAMPS the led is attached to machine power, not ESTOP: https://github.com/machinekit/machinekit/blob/master/configs/ARM/BeagleBone/CRAMPS/CRAMPS.hal#L239-L241 So, after resetting ESTOP, you still need to power on the machine. Send a EMC_TASK_STATE_ON command for that after sending the EMC_TASK_STATE_ESTOP_RESET.

As for the systemd service, I'm not entirely sure, but I would think you'll need:

ExecStart=/bin/bash /usr/bin/machinekit /home/machinekit/machinekit/configs/ARM/BeagleBone/CRAMPS/CRAMPS.ini

and set mkwrapper as the DISPLAY in CRAMPS.ini. At least, that's what I did before.

Alternatively use strahlex's python script to initialize everything. This is quite a bit cleaner imo: https://github.com/strahlex/QtQuickVcp/wiki/Testing-mkwrapper#create-a-run-script

zhivko commented 8 years ago

If I use execstart as you suggested I get:

machinekit@beaglebone:~$ sudo systemctl status pipecutter.service
pipecutter.service - Starts my pipecutter Machinekit configuration
      Loaded: loaded (/etc/systemd/system/pipecutter.service; enabled)
      Active: failed (Result: exit-code) since Sun, 29 Nov 2015 17:10:37 +0000; 1 months and 9 days ago
     Process: 793 ExecStart=/bin/bash /usr/bin/machinekit /home/machinekit/machinekit/configs/ARM/BeagleBone/CRAMPS/CRAMPS.ini (code=exited, status=255)
      CGroup: name=systemd:/system/pipecutter.service

Probably permission issue?

With:

ExecStart=/usr/bin/python /usr/bin/mkwrapper -ini /home/machinekit/machinekit/configs/ARM.BeagleBone.CRAMPS/CRAMPS.ini

I was able to see all machinekit services with avahi-browse --all. Do you still think this is not enough? Maybe this is the reason why sending EMC_TASK_STATE_ON doesn't work? But why then machinekit responds back with:

MT_EMCCMD_EXECUTED in case of MT_EMC_TASK_SET_STATE, EMC_TASK_STATE_ESTOP_RESET

and

MT_EMCCMD_COMPLETED in case of MT_EMC_TASK_SET_STATE, EMC_TASK_STATE_ON

I tried to send EMC_TASK_STATE_ON after resetting estop but I still cannot disable led on CRAMPS. This is code I used:

        pb.Message.Container.Builder builder = Container.newBuilder();
        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
                .newBuilder()
                .setTaskState(Status.EmcTaskStateType.EMC_TASK_STATE_ON).build();

        builder.setType(ContainerType.MT_EMC_TASK_SET_STATE);
        builder.setEmcCommandParams(emcCommandParameter);
        builder.setInterpName("execute");
        builder.setTicket(1);

        Container container = builder.build();

        byte[] buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
        System.out.println("Message: " + hexOutput);
        getSocket().send(buff);
        byte[] received = getSocket().recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Here are both commands and reply from BBB Machinekit with CRAMPS:

Message: 088952D2010765786563757465B80301922603A80602
type: MT_EMCCMD_EXECUTED
reply_ticket: 1

Message: 088952D2010765786563757465B80301922603A80604
type: MT_EMCCMD_COMPLETED
reply_ticket: 1
zhivko commented 8 years ago

I found cause why this is not executed. If I start machinekit on BBB with: machinekit [ini.file] Estop is reseted, poweed on and red led is off.

If i start it with systemctl with: ExecStart=/usr/bin/python /usr/bin/mkwrapper -ini /home/machinekit/machinekit/configs/ARM.BeagleBone.CRAMPS/CRAMPS.ini

Than it wont go off.

But i get acknowledge in each case what probably is not ok.

zhivko commented 8 years ago

Since now I have sshd way of starting machinekit, and estop reset via machinetalk works - any Idea how can I jog motors? What machinetalk structure I need to transfer to BBB, for moving any of 6 cramps steppers (x,y,z or a,b,c)?

bobvanderlinden commented 8 years ago

Here is an example: https://github.com/strahlex/QtQuickVcp/blob/5c566146834a0b21af0942d3c971b76f7ea18c52/src/application/qapplicationcommand.cpp#L182-L213

zhivko commented 8 years ago

Great! Jogging works and steppers run happily with:

    private void jogAxis(int axis, double velocity, double distance) {
        pb.Message.Container.Builder builder = Container.newBuilder();
        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
                .newBuilder()
                .setIndex(axis)
                .setVelocity(velocity)
                .setDistance(distance)
                .build();

        builder.setType(ContainerType.MT_EMC_AXIS_INCR_JOG);
        builder.setEmcCommandParams(emcCommandParameter);
        builder.setTicket(ticket++);
        Container container = builder.build();

        byte[] buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
        System.out.println("Message: " + hexOutput);
        getSocket().send(buff);
        byte[] received = getSocket().recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

but executing MDI with:

    private void executeMdi(String command) {
        pb.Message.Container.Builder builder = Container.newBuilder();
        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
                .newBuilder()
                .setCommand(command)
                .build();

        builder.setType(ContainerType.MT_EMC_TASK_PLAN_EXECUTE);
        builder.setEmcCommandParams(emcCommandParameter);
        builder.setInterpName("execute");
        builder.setTicket(ticket++);

        Container container = builder.build();

        byte[] buff = container.toByteArray();
        String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
        System.out.println("Message: " + hexOutput);
        getSocket().send(buff);
        byte[] received = getSocket().recv();
        try {
            Container contReturned = Container.parseFrom(received);
            contReturned.getType().toString();
            System.out.println(contReturned.toString());
        } catch (InvalidProtocolBufferException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

does nothing. I get this back:

Message: 088D52D2010765786563757465B8030592260B4A09473020583130302E30
type: MT_EMCCMD_COMPLETED
reply_ticket: 2

Do you maybe have idea what I am doing wrong?

bobvanderlinden commented 8 years ago

Is this being executed in MDI mode? Using MT_EMC_TASK_SET_MODE and task_mode set to EMC_TASK_MODE_MDI.

On Sun, Jan 10, 2016 at 8:45 PM zhivko notifications@github.com wrote:

Great! Jogging works with:

private void jogAxis(int axis, double velocity, double distance) {
    pb.Message.Container.Builder builder = Container.newBuilder();
    pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
            .newBuilder()
            .setIndex(axis)
            .setVelocity(velocity)
            .setDistance(distance)
            .build();

    builder.setType(ContainerType.MT_EMC_AXIS_INCR_JOG);
    builder.setEmcCommandParams(emcCommandParameter);
    builder.setTicket(ticket++);
    Container container = builder.build();

    byte[] buff = container.toByteArray();
    String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
    System.out.println("Message: " + hexOutput);
    getSocket().send(buff);
    byte[] received = getSocket().recv();
    try {
        Container contReturned = Container.parseFrom(received);
        contReturned.getType().toString();
        System.out.println(contReturned.toString());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

but executing MDI with:

private void executeMdi(String command) {
    pb.Message.Container.Builder builder = Container.newBuilder();
    pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters
            .newBuilder()
            .setCommand(command)
            .build();

    builder.setType(ContainerType.MT_EMC_TASK_PLAN_EXECUTE);
    builder.setEmcCommandParams(emcCommandParameter);
    builder.setInterpName("execute");
    builder.setTicket(ticket++);

    Container container = builder.build();

    byte[] buff = container.toByteArray();
    String hexOutput = javax.xml.bind.DatatypeConverter.printHexBinary(buff);
    System.out.println("Message: " + hexOutput);
    getSocket().send(buff);
    byte[] received = getSocket().recv();
    try {
        Container contReturned = Container.parseFrom(received);
        contReturned.getType().toString();
        System.out.println(contReturned.toString());
    } catch (InvalidProtocolBufferException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

does nothing. I get this back:

Message: 088D52D2010765786563757465B8030592260B4A09473020583130302E30 type: MT_EMCCMD_COMPLETED reply_ticket: 2

Do you maybe have idea what I am doing wrong?

— Reply to this email directly or view it on GitHub https://github.com/bobvanderlinden/node-machinetalk/issues/16#issuecomment-170384672 .

zhivko commented 8 years ago

Eh no - This are details I still miss... :) Thanks will try to do that... And another specifical - when I stop jogging should I do this:

if (type == StopJog)
    {
        containerType = pb::MT_EMC_AXIS_ABORT;
    }

?

bobvanderlinden commented 8 years ago

No, well, you could, but best would be to jog with a velocity of 0 to stop. Abort probably does more than just stopping a jog operation. @strahlex please correct me if I'm wrong ;)

On Sun, Jan 10, 2016 at 9:58 PM zhivko notifications@github.com wrote:

Eh no - This are details I still miss... :) Thanks will try to do that... And another specifical - when I stop jogging should I do this:

if (type == StopJog) { containerType = pb::MT_EMC_AXIS_ABORT; }

?

— Reply to this email directly or view it on GitHub https://github.com/bobvanderlinden/node-machinetalk/issues/16#issuecomment-170393431 .

zhivko commented 8 years ago

Now I see for:

        pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters.newBuilder().setIndex(axis)
                .setVelocity(velocity).setDistance(distance).build();

If I put axis=0 and axis=1 - it seems it doesn't move different motors but it moves same motor another time faster. I run it like:

        comm.jogAxis(0, 100.0, 20.0);
        comm.jogAxis(1, 100.0, 20.0);
        comm.jogAxis(2, 100.0, 20.0);

I expected I would be able to jog each of 3 (currently connected motors)... What are axis possible values for method:

pb.Status.EmcCommandParameters emcCommandParameter = pb.Status.EmcCommandParameters.newBuilder().setIndex(axis)

I am currently trying with 0,1 and 2 (this somehow seemed logical for axis number to be used)