ev3dev / ev3dev-lang

(deprecated) language bindings for ev3dev sensors, motors, LEDs, etc.
GNU General Public License v2.0
56 stars 39 forks source link

Java API for EV3Dev #114

Open jabrena opened 9 years ago

jabrena commented 9 years ago

Good morning,

I have created a repo to offer an API for Java developers using EV3Dev. https://github.com/jabrena/ev3dev-lang-java

I think that Python development has good progress. For other language, what is the best strategy to integrate with the native API? http://www.ev3dev.org/docs/sensors/ http://www.ev3dev.org/docs/motors/

I would like to create a easy example from Java to read a Sensor and use a motor for example. Later, if the PoC goes well, I would like to generate the API for the rest of elements. Is it possible to reuse low level development used from Python to other language?

Cheers

Juan Antonio

ddemidov commented 9 years ago

You should look into autogen system first. It has ev3dev specification in spec.json, and it can generate code from the specification with liquid template files. You can look at the templates for python here: https://github.com/rhempel/ev3dev-lang-python/tree/master/templates.

If you make the system work, then (almost) the only thing you need to implement is base Device class (see python version here) and the liquid templates. The rest of the classes with all the attributes are generated by autogen.

I think its completely OK to reuse Device implementation from either of the existing bindings.

jabrena commented 9 years ago

Many thanks @ddemidov

I will try to generate the infrastructure to run a basic example from Java and later, I start developing the whole support.

I think that working with the same technology, low-level problems could be solved in team.

Cheers

Juan Antonio

jabrena commented 9 years ago

Hi @ddemidov, @dlech, @rhempel

I have just tried to install dependencies with node, but I get the following error:

➜  autogen  npm install
npm WARN package.json ev3dev-lang-autogen@1.0.0 No repository field.
npm WARN package.json ev3dev-lang-autogen@1.0.0 No license field.
npm ERR! git clone --template=/Users/jabrena/.npm/_git-remotes/_templates --mirror git://github.com/WasabiFan/liquid-node.git /Users/jabrena/.npm/_git-remotes/git-github-com-WasabiFan-liquid-node-git-344bec5b: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.0.0
npm ERR! npm  v2.11.2
npm ERR! code 1

npm ERR! Command failed: git clone --template=/Users/jabrena/.npm/_git-remotes/_templates --mirror git://github.com/WasabiFan/liquid-node.git /Users/jabrena/.npm/_git-remotes/git-github-com-WasabiFan-liquid-node-git-344bec5b
npm ERR! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! 
npm ERR! 

It says something about a problem an invalid active developer path.

Any idea to fix the problem?

Cheers

Juan Antonio

dlech commented 9 years ago

@WasabiFan is the node.js guy.

It looks like maybe you are trying to install this on a Mac. It is meant to install on the EV3 itself.

ddemidov commented 9 years ago

you need to run npm install from autogen folder. If that does not work, we need to ask @WasabiFan, he is the author of autogen system.

ddemidov commented 9 years ago

And it will work out of ev3, no need to install it there.

dlech commented 9 years ago

Oh, wait. You are tying to run the autogen. I though you were trying to run the node.js binding. So never mind.

dlech commented 9 years ago

Do you have XCode command line tools installed?

jabrena commented 9 years ago

I think that I don't have that tool:

➜  autogen  XCode
zsh: command not found: XCode

Is it necessary to be installed XCode on Mac? Is it enough with gcc?

jabrena commented 9 years ago

I read a bit and I have installed them:

➜  autogen  xcode-select -p
/Library/Developer/CommandLineTools

➜  autogen  xcode-select -v
xcode-select version 2343.
jabrena commented 9 years ago

I was reading a bit.

I am installing

xcode-select --install

I will test again, in a while

jabrena commented 9 years ago

Installed.

➜  autogen git:(develop) node autogen.js
Queuing 5 file groups...
Completed processing file "python/spec_version.py"
Completed processing file "cpp/ev3dev-lang-demo.cpp"
Completed processing file "js/sensor.ts"
Completed processing file "cpp/ev3dev.cpp"
Completed processing file "js/motor.ts"
Completed processing file "js/extras.ts"
Completed processing file "cpp/ev3dev-lang-test.cpp"
Completed processing file "cpp/ev3dev.h"
Completed processing file "wrapper-specification.md"
Completed processing file "python/ev3dev.py"
Completed processing file "lua/ev3dev.lua"

I suppose that I have observe the way for the rest of language to to the same for Java, isn't it?

dlech commented 9 years ago

Yes. Python has most recently been updated, so use that for your guide.

jabrena commented 9 years ago

Ok, Tomorrow, I will research a bit about the system. Many thanks

WasabiFan commented 9 years ago

Looks like this was resolved. Is there anything I should change about the autogen system to make it clearer/work better?

P.S. Sorry I haven't been involved in the discussions these past weeks -- very busy! I plan to try to get caught up soon.

jabrena commented 9 years ago

Hi,

the process to install the autogen infrastructure is clear, maybe we could update the documentation to add the commands for Mac to ensure that everybody with mac has Xcode installed.

xcode-select --install

Once, the developer has installed the system, the developer tests autogen with the following node command:

node autogen.js

for python, the parts generated by the templates defined on: https://github.com/rhempel/ev3dev-lang-python/tree/master/templates

Completed processing file "python/spec_version.py"
Completed processing file "python/ev3dev.py"

the system binds with templates in python in the file:

autogen-list.json

    "python": {
        "files": [
            "python/ev3dev.py",
            "python/spec_version.py"
        ],
        "templateDir": "python/templates/"
    },

but what is the mechanics?

I have added a local copy of the repo for java on ev3dev-lang in the same level of other language: https://github.com/jabrena/ev3dev-lang-java

this project has 2 output files:

In theory, autogen will update both files.

In autogen folder i updated the file to add java language but I only added a first file to experiment:

    "java": {
        "files": [
            "java/ev3dev.java"
        ],
        "templateDir": "java/templates/"
    },

ev3dev.java:

//~autogen ../java/templates/java_spec_version
spec_version = "spec: 0.9.3-pre-r1, kernel: v3.16.7-ckt10-4-ev3dev-ev3"

//~autogen

I suppose that autogen get the content of the .liquid template and paste the content into the file, but currently with this idea, i receive the following error:


➜  autogen git:(develop) ✗ node autogen
Queuing 6 file groups...
Completed processing file "python/spec_version.py"
/Users/jabrena/Documents/DATA/2015/RESEARCH/robotics/ev3dev/java/ev3dev-lang/autogen/autogen.js:189
    if (commentInfo.start instanceof RegExp)
                   ^

TypeError: Cannot read property 'start' of undefined
    at processNextAutogenBlock (/Users/jabrena/Documents/DATA/2015/RESEARCH/robotics/ev3dev/java/ev3dev-lang/autogen/autogen.js:189:20)
    at /Users/jabrena/Documents/DATA/2015/RESEARCH/robotics/ev3dev/java/ev3dev-lang/autogen/autogen.js:175:9
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

If you add the in .gitmodules this part:

[submodule "java"]
    path = java
    url = https://github.com/jabrena/ev3dev-lang-java
    branch = master

you could observe the error.

The idea is pretty interesting. In python exist other combinations more advanced but at the moment, the most easiest way, I can't update the first file.

Juan Antonio

ddemidov commented 9 years ago

Here is what you need to do:

  1. Add a line for java here. You may just copy the line for cpp I think. This will tell autogen how its markers look like in java files.
  2. After this, autogen will look for lines starting with //~autogen in the files that you specifed here. Start of the autogen block should look like this:
//~autogen java_spec_version

There is no need to specify full relative path as long as you've told autogen where to look for the templates. I know python spec_version.py does this, but this is a leftover overlooked by me and @rhempel.

By the way, you can run autogen just for java by node ../autogen/autogen.js java. This way you won't touch other people's bindings and won't commit the changes accidentally.

jabrena commented 9 years ago

Right!!!

Now, I begin seeing the light!!

Updating the file:

    '.py': { start: /#~autogen *([\w-]+) *((\s*[\w\."']+>[\w\.]+)*)/, end: "#~autogen" },
    '.java': { start: cStyleAutogenStart, end: cStyleAutogenEnd }

I can update the files defined here:

    "java": {
        "files": [
            "java/ev3dev.java",
            "java/spec_version.java"
        ],
        "templateDir": "java/templates/"
    },

Results:

➜  autogen git:(develop) ✗ node autogen.js java
Queuing 1 file groups...
Completed processing file "java/ev3dev.java"
Completed processing file "java/spec_version.java"

Besides, you have reason, sending the parameter java is safer to not update other bindings. This afternoon, I will continue researching more about templates.

Juan Antonio

rhempel commented 9 years ago

Welcome to the club Juan Antonio - I think you will like this project and we look forward to your contributions on the Java binding.

jabrena commented 9 years ago

hehehe,

Yes this idea is Smart because the system deacoplates languages from low level and this is the way to increase the scalability of the project. Anyway, I will need some hours to get the first result for Java binding.

I continue with the researching!!! :D

WasabiFan commented 8 years ago

This is going to be held back until next release. Initial PR in #134.