googlecreativelab / coder

A simple way to make web stuff on Raspberry Pi
http://goo.gl/coder
Apache License 2.0
2.42k stars 276 forks source link

Running Lego Mindstorms from Google Coder #49

Open karan259 opened 10 years ago

karan259 commented 10 years ago

I am working on the BrickPi(http://www.dexterindustries.com/BrickPi/) which a shield for Raspberry Pi which controls the various sensors and motors on the Lego Mindstorms from the RPi itself. We have a library up and working on Python and C (https://github.com/karan259/BrickPi_Python). Now we want to use Google Coder so that users can directly run the Python code from the Google Coder, i.e, directly from the browser and don't want to port the whole library to JavaScript or any other language.

We have tried a Python-to-JavaScript compiler (Pyjaco) but that didn't help much , now going to try out RPC using ZeroRPC(http://zerorpc.dotcloud.com/). Does anyone have experience in this kind of environment can annyone suggest if there is a better way to do this.

ericgundrum commented 10 years ago

Unfortunately I have zero experience with what you are trying to do. However, my reading suggests you should be able to wrap your library as a node.js module with a JavaScript interface. Then, with your node module installed, it would be easy to call it from the Node page of a Coder app. With a little more JavaScript and html you could provide the front end and complete your app.

I imagine the hardest part is wrapping your python code in a module. I'd look for existing modules that might serve as examples of wrapping non-js code. I think this is how node is implemented, so there should be plenty of examples. And, maybe the node docs have a detailed explanation.

I found wikipedia a good place to start when learning about node: http://en.wikipedia.org/wiki/Node.js

jmstriegel commented 10 years ago

@karan259 this is great. I think that if I were going about this, instead of cross compiling, I'd create a little daemon in Python that exposes a simple http/json API on a port on localhost. Then you can talk to that daemon easily from node.js in coder. You could also make a nice bundle in Coder, say "BrickPiLib", that provides a common library/interface for front end and back end javascript to to shuttle commands to the lego modules.

Your Python daemon probably needs to keep track of all the sensors and motors and then expose api endpoints like the following, and any coder node.js -- or a nice wrapper you make in BrickPiLib ;) -- should be able to talk to it fairly easily.

POST /sensor/[0,1,2]
data:
'type': [touch,temp,light,...]

GET /sensors returned data: { sensors: [ { 'type': 'touch', 'value': 'pressed' }, { 'type': 'raw', 'value': .0012 }, { 'type': 'temp', 'value': 101.03 } ] }

POST /motor/[0,1,2] data: 'direction': [0,1] 'speed': 50 ...

GET /motors returned data: { motors: [ { 'direction': 0, 'rotation': 3, 'speed': 50 }, { 'direction': 1, 'rotation': 0, 'speed': 59 }, { 'direction': 0, 'rotation': 12, 'speed': 0 }, ] }

karan259 commented 10 years ago

@ericgundrum Creating a Node.js module is one way of going forward but since I have zero experience in that, it might be too much for me at this time. @jmstriegel using a python daemon with JSON looks like a good way forward. It may even allow us to support other languages too. Thanks for the reply

joesanford commented 10 years ago

Hi Karan,

I have developed (and am continuing to develop) a system that works with the BrickPi, which includes using Coder itself as well as another Google tool, Blockly. Feel free to check out our code here: https://github.com/tufts-LPC/blockytalky

coffeechug commented 10 years ago

So, this may sound like a super stupid question so pardon my lack of awareness, but I am really interested in what you are sharing here. What actual parts do I need to experiment with this code and your ideas?

On Mon, Nov 18, 2013 at 4:03 PM, Joe notifications@github.com wrote:

Hi Karan,

I have developed (and am continuing to develop) a system that works with the BrickPi, which includes using Coder itself as well as another Google tool, Blockly. Feel free to check out our code here: https://github.com/tufts-LPC/blockytalky

— Reply to this email directly or view it on GitHubhttps://github.com/googlecreativelab/coder/issues/49#issuecomment-28742704 .

------------------------------------------------- Aaron Maurer

--------------------------------------------------Q: Why is this email five sentences or less?A: http://five.sentenc.es http://five.sentenc.es MY BLOG http://coffeeforthebrain.blogspot.com/ ABOUT ME http://coffeeforthebrain.blogspot.com/p/coffee-for-brain-book-swap.html TWITTER https://twitter.com/coffeechugbooks GOOGLE + https://plus.google.com/u/0/113960577497815089175/posts

This email is off the record (blogs and tweets too) unless we agree otherwise.

joesanford commented 10 years ago

If you have the BrickPi (and I'm assuming a Raspberry Pi since you're looking at Coder) you already have everything you need to get going. Just clone the repo, follow the install instructions, and you'll be off and going. BlockyTalky works side by side with Coder, and we hope to soon add functionality in Coder to create interfaces for BlockyTalky.