ev3dev / lms2012-compat

lms2012 VM compatibility layer for ev3dev
http://www.ev3dev.org
7 stars 4 forks source link

Executing code from EV3-G program #37

Open laurensvalk opened 7 years ago

laurensvalk commented 7 years ago

This may be something optional for future development, but possibly not the hardest to implement.

One way to let EV3-G programs access the other ev3dev features could be implemented in the lms2012-compat application, without requiring any Labview toolkits:

Whenever a user writes something to one special file (its name hardcoded in lms2012, e.g. run), the text is not stored in the file, but executed as if it were typed on the command line. In this example, "beep" is executed.

runev3g

But it could also be a python script, and so on, which makes pretty much anything possible.

This is a variation of the previous discussion here https://github.com/ev3dev/ev3dev/issues/329#issuecomment-108919405

Of course, security is an issue if lms2012 runs as root.

[Edited post to change example with new picture]

jabrena commented 7 years ago

@laurensvalk, it could run but it is necessary some kind of daemon reading the content of the folder to understand the special names of the Domain Language.

dlech commented 7 years ago

There is already a SYSTEM command in the VM. This would be ideal, but as you said, we would need some sort of LabView toolkit because there is no "gray blob" for it in the EV3 Block Developer Kit on the official MINDSTORMS site.

Using file blocks could work, but I think we should namespace the special files, e.g. ev3dev:run.

To make it even more versatile, you would probably want ev3dev:run-wait and ev3dev:run-no-wait depending on if you want to wait for the command to complete before moving to the next instruction block.

laurensvalk commented 7 years ago

If this is eventually implemented with the file block, I'll volunteer to make a My Block around it.

The My Block can have a checkbox "Wait For Completion", and so on.

On the inside, this My Block can create the appropriate strings like ev3dev:run-wait depending on the selected options, and run the File Block with these settings.

Maybe the standard output could be redirected to a special file as well, which the My Block could return as a string array.

laurensvalk commented 7 years ago

Here's a simple demo:

https://www.youtube.com/watch?v=jXpAasYZX4A

In these examples, a shell script is continuously waiting (inotify-tools) for a text file to change, after which it runs a specified script (espeak/aplay and fswebcam).

jabrena commented 7 years ago

Hi @laurensvalk,

How to upload your example on ev3dev? using scp command in some path?

Another advantage that I observe to combine ev3dev with EV3-G is math accuracy. With EV3-G, the objects only store 4 digits. for navigation features this fact accumulate errors. For example any calculus with Math.Pi or Math.Atan2

Cheers

Juan Antonio

laurensvalk commented 7 years ago

In the speech example, the EV3-G program writes a string "Here I am ...." to a file called "string.rbf". (The Speak My Block is nothing more than two File blocks to erase the old string and write a new one.)

Separately, this is running in the shell, in this case from the home directory:

while ./sleep_until_modified.sh /var/lib/lms2012/prjs/speaker/string.rtf ; do less -XF /var/lib/lms2012/prjs/speaker/string.rtf | espeak --stdout -ven-us -s110 | aplay ; done

'speaker' is the name of the EV3-G project. I used 'less -XF' instead of 'cat' because EV3-G writes weird Windows characters that 'cat' doesn't handle very well.

This works fine, but it is a bit hacky, and hence the proposals for a cleaner solution in this and the linked thread.

The second example works in the same way, but I run fswebcam in place of espeak/aplay.

jabrena commented 7 years ago

Hi @laurensvalk,

So you moved from your laptop to EV3Brick the project "speaker" to the folder:

/var/lib/lms2012/prjs/

the whole project and later, you executed the program string.rtf, isn´t it?

while ./sleep_until_modified.sh /var/lib/lms2012/prjs/speaker/string.rtf ; 
do less -XF /var/lib/lms2012/prjs/speaker/string.rtf | espeak --stdout -ven-us -s110 | aplay ; done

I will study the script: "./sleep_until_modified.sh" https://bitbucket.org/denilsonsa/small_scripts/src/78fb99fcb044/sleep_until_modified.sh?at=default&fileviewer=file-view-default

I think that lms-compact could be many possibilities for teachers to execute a gradual migration from visual environments to programming languages.

Cheers

Juan Antonio

laurensvalk commented 7 years ago

So you moved from your laptop to EV3Brick the project "speaker" to the folder: /var/lib/lms2012/prjs/ the whole project and later, you executed the program string.rtf, isn´t it?

No, 'speaker' is an EV3-G project, which is automatically stored in /var/lib/lms2012/prjs/ when you press download in the EV3-G environment. Also, string.rtf is not a program, but a text file created by the EV3-G program.

Sorry I didn't list all the steps involved, it was only meant as a demo of the potential of combining ev3dev with EV3-G. There are probably much better solutions for doing this.