yoelk / instrumentino

Instrumentino is an open-source modular graphical user interface framework for controlling Arduino based experimental instruments
GNU General Public License v3.0
137 stars 59 forks source link

Example code for simple system #1

Closed 1am closed 9 years ago

1am commented 9 years ago

Hi

It there an example for Arduino which would show how Instrumentino works out of the box? I've tried following the "Using Instrumentino" document and ended up with something like this:

from __future__ import division
from instrumentino import Instrument
from instrumentino import cfg
from instrumentino.action import SysAction

from instrumentino.controllers.arduino.parker import ParkerPressureController
from instrumentino.controllers.labsmith_eib.labsmith_comps import LabSmithValves4VM01
from instrumentino.controllers.arduino.parker import ParkerPressureController

from instrumentino.action import SysActionParamTime, SysActionParamFloat

pinAnalInParkerP = 5
pinPwmOutParkerP = 9
pressureController = ParkerPressureController('Pressure', (0,100), pinAnalInParkerP, pinPwmOutParkerP, highFreqPWM=True)

class SysActionFillContainer(SysAction):
    def __init__(self):
        self.seconds = SysActionParamTime()
        self.psi = SysActionParamFloat(pressureController.vars['P'])
        SysAction.__init__(self, 'Fill Container', (self.seconds, self.psi))

    def Command(self):
        # Connect container to pressure controller
        #valves.vars['V1'].Set(valvePortPressure)

        # Start pressure
        pressureController.vars['P'].Set(self.psi.Get())

        # Wait some time
        cfg.Sleep(self.seconds.Get())

        # Close container
        #valves.vars['V1'].Set('closed')

class System(Instrument):
    def __init__(self):
        comps = (pressureController)#, valves)
        actions = (SysActionFillContainer())
                   #SysActionEmptyContainer())
        name = 'Example System'
        description = 'A container connected to a pressure controller'
        version = '1.0'         
        Instrument.__init__(self, comps, actions, version, name, description)

if __name__ == '__main__':
    # run the program
    System()

And just after starting the script it fails with the following error:

# python instrumentino-test.py 
Traceback (most recent call last):
  File "instrumentino-test.py", line 48, in <module>
    System()
  File "instrumentino-test.py", line 44, in __init__
    Instrument.__init__(self, comps, actions, version, name, description)
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/__init__.py", line 359, in __init__
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/__init__.py", line 371, in StartApp
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/__init__.py", line 32, in __init__
  File "/usr/local/lib/wxPython-3.0.1.1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py", line 8628, in __init__
    self._BootstrapApp()
  File "/usr/local/lib/wxPython-3.0.1.1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py", line 8196, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/__init__.py", line 39, in OnInit
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/__init__.py", line 54, in InitFrame
  File "build/bdist.macosx-10.6-i386/egg/instrumentino/log_graph.py", line 66, in __init__
TypeError: 'ParkerPressureController' object is not iterable

I'd really like to give it a try but can't make it work probably due to some small mistake I'm making.

1am commented 9 years ago

:) found them in https://github.com/yoelk/Instrumentino/tree/master/documents/

yoelk commented 9 years ago

Hi Piotr, The problem is that in the components line, you need a comma (,) after the component: comps = (pressureController,)#, valves) instead of: comps = (pressureController)#, valves)

It's a thing with tuples in python. Single item tuples should be like that: (item,)

Hope it helps.

Could you tell me what you would be using Instrumentino for? I'm very interested to know and get feedback.

Thanks, Joel

On Thu, Nov 6, 2014 at 4:33 PM, Piotr notifications@github.com wrote:

Hi

It there an example for Arduino which would show how Instrumentino works out of the box? I've tried following the "Using Instrumentino" document and ended up with something like this:

from future import divisionfrom instrumentino import Instrumentfrom instrumentino import cfgfrom instrumentino.action import SysAction from instrumentino.controllers.arduino.parker import ParkerPressureControllerfrom instrumentino.controllers.labsmith_eib.labsmith_comps import LabSmithValves4VM01from instrumentino.controllers.arduino.parker import ParkerPressureController from instrumentino.action import SysActionParamTime, SysActionParamFloat

pinAnalInParkerP = 5 pinPwmOutParkerP = 9 pressureController = ParkerPressureController('Pressure', (0,100), pinAnalInParkerP, pinPwmOutParkerP, highFreqPWM=True) class SysActionFillContainer(SysAction): def init(self): self.seconds = SysActionParamTime() self.psi = SysActionParamFloat(pressureController.vars['P']) SysAction.init(self, 'Fill Container', (self.seconds, self.psi))

def Command(self):
    # Connect container to pressure controller
    #valves.vars['V1'].Set(valvePortPressure)

    # Start pressure
    pressureController.vars['P'].Set(self.psi.Get())

    # Wait some time
    cfg.Sleep(self.seconds.Get())

    # Close container
    #valves.vars['V1'].Set('closed')

class System(Instrument): def init(self): comps = (pressureController)#, valves) actions = (SysActionFillContainer())

SysActionEmptyContainer())

    name = 'Example System'
    description = 'A container connected to a pressure controller'
    version = '1.0'
    Instrument.**init**(self, comps, actions, version, name, description)

if name == 'main':

run the program

System()

And just after starting the script it fails with the following error:

python instrumentino-test.py

Traceback (most recent call last): File "instrumentino-test.py", line 48, in System() File "instrumentino-test.py", line 44, in init Instrument.init(self, comps, actions, version, name, description) File "build/bdist.macosx-10.6-i386/egg/instrumentino/init.py", line 359, in init File "build/bdist.macosx-10.6-i386/egg/instrumentino/init.py", line 371, in StartApp File "build/bdist.macosx-10.6-i386/egg/instrumentino/init.py", line 32, in init File "/usr/local/lib/wxPython-3.0.1.1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py", line 8628, in init self._BootstrapApp() File "/usr/local/lib/wxPython-3.0.1.1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py", line 8196, in _BootstrapApp return core.PyApp__BootstrapApp(_args, *_kwargs) File "build/bdist.macosx-10.6-i386/egg/instrumentino/init.py", line 39, in OnInit File "build/bdist.macosx-10.6-i386/egg/instrumentino/init.py", line 54, in InitFrame File "build/bdist.macosx-10.6-i386/egg/instrumentino/log_graph.py", line 66, in init TypeError: 'ParkerPressureController' object is not iterable

I'd really like to give it a try but can't make it work probably due to some small mistake I'm making.

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1.

1am commented 9 years ago

Thank you. Your comment made my example work.

I want to use it for logging various long term measurements and I'm doing a lot of them lately. BTW. Is an action a good place to add pushing data to remote API or is there a better way to do it? I'm asking mainly about what happens if for example sync HTTP requests would be executed in actions?

yoelk commented 9 years ago

Ah, good question. If your action would look like this:

you could run it continuously from the Sequence panel, and I believe it would work.

Another option would be to incorporate your API in the Instrumentino framework, and add it as an option in the menus or something like that.

I'm looking for fellow developers for Instrumentino, and if you're interested, we can extend its functionality to the benefit of other users.

Thanks for the feedback! Joel

On Thu, Nov 6, 2014 at 5:22 PM, Piotr notifications@github.com wrote:

Thank you. Your comment made my example work.

I want to use it for logging various long term measurements and I'm doing a lot of them lately. BTW. Is an action a good place to add pushing data to remote API or is there a better way to do it? I'm asking mainly about what happens if for example sync HTTP requests would be executed in actions?

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-62005098.

arnaldoarmida commented 9 years ago

Hi Yoelk, I want to thank you for your wonderful job you did for the community. It's really a great job. I'm a beginner so forgive me for the question I'm asking. I have tried to run the ArduinoPins.py and I have got the following error: File "/Users/arnaldoarmida/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/wx/_core.py", line 9939, in Enable return core.Window_Enable(_args, *_kwargs) TypeError: in method 'Window_Enable', expected argument 2 of type 'bool' I have attached some screenshot. Can you please give me some help? Thanks again and sorry disturbing you. Arnaldo

instrumentino_immaginepng

I

yoelk commented 9 years ago

Hi Arnaldo, I'm sorry you got such a strange error message. I'm not sure why it happened. Since the ArduinoPins example was written, I've updated Instrurmentino a few times (see GitHub) so maybe something got wrong. Instead, I suggest that you run the new example I recently added, built into the init.py file under the instrumentino folder.

I'm on my way to add more example projects, but haven't had enough time to do it yet...

Please tell me if you run into more problems... Joel

On Fri, Dec 5, 2014 at 11:10 PM, arnaldoarmida notifications@github.com wrote:

Hi Yoelk, I want to thank you for your wonderful job you did for the community. It's really a great job. I'm a beginner so forgive me for the question I'm asking. I have tried to run the ArduinoPins.py and I have got the following error: File "/Users/arnaldoarmida/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/wx/ _core.py", line 9939, in Enable return core.Window_Enable(args, * kwargs) TypeError: in method 'Window_Enable', expected argument 2 of type 'bool' I have attached some screenshot. Can you please give me some help? Thanks again and sorry disturbing you. Arnaldo

[image: instrumentino_immaginepng] https://cloud.githubusercontent.com/assets/8985532/5323767/ce2a450e-7cd3-11e4-814a-15c592e9c1bf.png

I

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65862738.

arnaldoarmida commented 9 years ago

Hi Yoel, first of all thank you very much for quick and kind reply. I have downloaded the new files on github. I ahve also moved on linux Mint last version where I have other python files running. The situationi is not changed and I still have the same problem on the Com ports. I have attached the related screenshots..same wrong messages.. Of course I have also tryied on Mac with the same results. I'm really sorry to disturb you but I think that somebody else should have the same problem or maybe is just my fault. Considering yuir kindness I take the liberty to ask you an other question about controlino. How to handle that files? I have copied and pasted controlino.cpp on my arduino Ide(1.0) but there is a compiling error as shown in the attached files. I'm really sorry for all those questions I'm putting to you...but this is the price to be paied to learn! Thank a lot. Arnaldo

PS. There is in your University a group working on LSC ( Luminescent Solra Concentrators)? I'm a coordinator of an interesting project on this...and I'm looking for some good research group to join us ( I have already Franunhofer, Rome Tor Vergata University,...). It should be ineteresting to know.

dr. Ing. Arnaldo Armida COORDINATOR:ENHARWIN EU PROJECT

Tel: +39 02 94750538 /+39 02 87167756 Fax:+39 02 87162693 Mobile: +39 393 1890639

E-Mail: arnaldo.armida@gmail.com

Le informazioni contenute nella comunicazione che precede possono essere riservate e sono, comunque, destinate esclusivamente alla persona o all'ente sopraindicati. La diffusione, distribuzione e/o copiatura del documento trasmesso da parte di qualsiasi soggetto diverso dal destinatario è proibita. La sicurezza e la correttezza dei messaggi di posta elettronica non possono essere garantite. Se avete ricevuto questo messaggio per errore, Vi preghiamo di contattarci immediatamente. Grazie.

2014-12-07 13:37 GMT+01:00 yoelk notifications@github.com:

Hi Arnaldo, I'm sorry you got such a strange error message. I'm not sure why it happened. Since the ArduinoPins example was written, I've updated Instrurmentino a few times (see GitHub) so maybe something got wrong. Instead, I suggest that you run the new example I recently added, built into the init.py file under the instrumentino folder.

I'm on my way to add more example projects, but haven't had enough time to do it yet...

Please tell me if you run into more problems... Joel

On Fri, Dec 5, 2014 at 11:10 PM, arnaldoarmida notifications@github.com wrote:

Hi Yoelk, I want to thank you for your wonderful job you did for the community. It's really a great job. I'm a beginner so forgive me for the question I'm asking. I have tried to run the ArduinoPins.py and I have got the following error: File

"/Users/arnaldoarmida/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/wx/

_core.py", line 9939, in Enable return core.Window_Enable(args, * kwargs) TypeError: in method 'Window_Enable', expected argument 2 of type 'bool' I have attached some screenshot. Can you please give me some help? Thanks again and sorry disturbing you. Arnaldo

[image: instrumentino_immaginepng] < https://cloud.githubusercontent.com/assets/8985532/5323767/ce2a450e-7cd3-11e4-814a-15c592e9c1bf.png>

I

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65862738.

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65936012.

yoelk commented 9 years ago

Hi Arnaldo, no problem. I couldn't see any screenshots, probably because it's through the GitHub system. You can contact me on yoelk@tx.technion.ac.il.

But nevermind about it, if you haven't uploaded a working version of controlino to your Arduino, this would explain everything. Controlino is the slave program running on the Arduino, that communicates with Instrumentino. If you couldn't compile it, it's probably because you don't have the necessary libraries installed (SoftwareSerial, PID, etc.) Please look at the compilation errors and solve them by downloading the necessary libraries.

When you've done this, everything should work.

I don't know much about LSC, sorry I can't help much there. Joel

On Sun, Dec 7, 2014 at 5:19 PM, arnaldoarmida notifications@github.com wrote:

Hi Yoel, first of all thank you very much for quick and kind reply. I have downloaded the new files on github. I ahve also moved on linux Mint last version where I have other python files running. The situationi is not changed and I still have the same problem on the Com ports. I have attached the related screenshots..same wrong messages.. Of course I have also tryied on Mac with the same results. I'm really sorry to disturb you but I think that somebody else should have the same problem or maybe is just my fault. Considering yuir kindness I take the liberty to ask you an other question about controlino. How to handle that files? I have copied and pasted controlino.cpp on my arduino Ide(1.0) but there is a compiling error as shown in the attached files. I'm really sorry for all those questions I'm putting to you...but this is the price to be paied to learn! Thank a lot. Arnaldo

PS. There is in your University a group working on LSC ( Luminescent Solra Concentrators)? I'm a coordinator of an interesting project on this...and I'm looking for some good research group to join us ( I have already Franunhofer, Rome Tor Vergata University,...). It should be ineteresting to know.

dr. Ing. Arnaldo Armida COORDINATOR:ENHARWIN EU PROJECT

Tel: +39 02 94750538 /+39 02 87167756 Fax:+39 02 87162693 Mobile: +39 393 1890639

E-Mail: arnaldo.armida@gmail.com

Le informazioni contenute nella comunicazione che precede possono essere riservate e sono, comunque, destinate esclusivamente alla persona o all'ente sopraindicati. La diffusione, distribuzione e/o copiatura del documento trasmesso da parte di qualsiasi soggetto diverso dal destinatario è proibita. La sicurezza e la correttezza dei messaggi di posta elettronica non possono essere garantite. Se avete ricevuto questo messaggio per errore, Vi preghiamo di contattarci immediatamente. Grazie.

2014-12-07 13:37 GMT+01:00 yoelk notifications@github.com:

Hi Arnaldo, I'm sorry you got such a strange error message. I'm not sure why it happened. Since the ArduinoPins example was written, I've updated Instrurmentino a few times (see GitHub) so maybe something got wrong. Instead, I suggest that you run the new example I recently added, built into the init.py file under the instrumentino folder.

I'm on my way to add more example projects, but haven't had enough time to do it yet...

Please tell me if you run into more problems... Joel

On Fri, Dec 5, 2014 at 11:10 PM, arnaldoarmida notifications@github.com

wrote:

Hi Yoelk, I want to thank you for your wonderful job you did for the community. It's really a great job. I'm a beginner so forgive me for the question I'm asking. I have tried to run the ArduinoPins.py and I have got the following error: File

"/Users/arnaldoarmida/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/wx/

_core.py", line 9939, in Enable return core.Window_Enable(args, * kwargs) TypeError: in method 'Window_Enable', expected argument 2 of type 'bool' I have attached some screenshot. Can you please give me some help? Thanks again and sorry disturbing you. Arnaldo

[image: instrumentino_immaginepng] <

https://cloud.githubusercontent.com/assets/8985532/5323767/ce2a450e-7cd3-11e4-814a-15c592e9c1bf.png>

I

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65862738.

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65936012.

— Reply to this email directly or view it on GitHub https://github.com/yoelk/Instrumentino/issues/1#issuecomment-65942621.