Bonjour,
dans le cadre de projet de fin d'année de prépas scientifique, j'ai créé une plateforme de force composé de 4 capteurs de force relié ensemble par un pont *PHIDGETS* .
Mon objectif est d'extraire les valeurs des capteurs afin d'en calculer le barycentre.

Si certains connaissent, il s'agit de l'_Interface Phidget 1046_. Avec ceci était disponible un programme python (plus bas dans le post).

_NB_: Il est nécessaire d'installer la bibliothèque Phidgets de Python pour en utiliser les fonctions.
bibliothèque disponible ici:` http://www.phidgets.com/docs/Language_-_Python#Installing_the_Phidget_Python_Module`

*Comment extraire les valeurs de l'interface? Comment les transformer sous forme de liste indépendante?*

```ruby
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/python
 
"""Copyright 2011 Phidgets Inc.
This work is licensed under the Creative Commons Attribution 2.5 Canada License.
To view a copy of this license, visit <a href="http://creativecommons.org/licenses/by/2.5/ca/" target="_blank">http://creativecommons.org/licenses/by/2.5/ca/</a>
"""
 
__author__="Adam Stelmack"
__version__="2.1.8"
__date__ ="14-Jan-2011 2:29:14 PM"
 
#Basic imports
import sys
from time import sleep
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetException
from Phidgets.Devices.Bridge import Bridge, BridgeGain
from Phidgets.Phidget import PhidgetLogLevel
 
#Create an accelerometer object
try:
    bridge = Bridge()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)
 
#Information Display Function
def displayDeviceInfo():
    print("|------------|----------------------------------|--------------|------------|")
    print("|- Attached -|-              Type              -|- Serial No. -|-  Version -|")
    print("|------------|----------------------------------|--------------|------------|")
    print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (bridge.isAttached(), bridge.getDeviceName(), bridge.getSerialNum(), bridge.getDeviceVersion()))
    print("|------------|----------------------------------|--------------|------------|")
    print("Number of bridge inputs: %i" % (bridge.getInputCount()))
    print("Data Rate Max: %d" % (bridge.getDataRateMax()))
    print("Data Rate Min: %d" % (bridge.getDataRateMin()))
    print("Input Value Max: %d" % (bridge.getBridgeMax(0)))
    print("Input Value Min: %d" % (bridge.getBridgeMin(0)))
 
#Event Handler Callback Functions
def BridgeAttached(e):
    attached = e.device
    print("Bridge %i Attached!" % (attached.getSerialNum()))
 
def BridgeDetached(e):
    detached = e.device
    print("Bridge %i Detached!" % (detached.getSerialNum()))
 
def BridgeError(e):
    try:
        source = e.device
        print("Bridge %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
 
def BridgeData(e):
    source = e.device
    print("Bridge %i: Input %i: %f" % (source.getSerialNum(), e.index, e.value))
 
#Main Program Code
try:
	#logging example, uncomment to generate a log file
    #bridge.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log")
 
    bridge.setOnAttachHandler(BridgeAttached)
    bridge.setOnDetachHandler(BridgeDetached)
    bridge.setOnErrorhandler(BridgeError)
    bridge.setOnBridgeDataHandler(BridgeData)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)
 
print("Opening phidget object....")
 
try:
    bridge.openPhidget()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)
 
print("Waiting for attach....")
 
try:
    bridge.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        bridge.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()
 
try:
    print("Set data rate to 8ms ...")
    bridge.setDataRate(16)
    sleep(2)
 
    print("Set Gain to 8...")
    bridge.setGain(0, BridgeGain.PHIDGET_BRIDGE_GAIN_8)
    sleep(2)
 
    print("Enable the Bridge input for reading data...")
    bridge.setEnabled(0, True)
    sleep(2)
 
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        bridge.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
 
print("Press Enter to quit....")
 
chr = sys.stdin.read(1)
 
print("Closing...")
 
try:
    print("Disable the Bridge input for reading data...")
    bridge.setEnabled(0, False)
    sleep(2)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        bridge.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
 
try:
    bridge.closePhidget()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)
 
print("Done.")
exit(0)
```

Lorsqu'on lance le programme (si les capteur sont branché et activé), la console renvoie:

```ruby
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Opening phidget object....
Waiting for attach....
Bridge 469514 Attached!
Bridge 469514: Input 0: -0.019670
Bridge 469514: Input 1: -0.066880
Bridge 469514: Input 2: -0.054000
Bridge 469514: Input 3: 0.072000
|------------|----------------------------------|--------------|------------|
|- Attached -|-              Type              -|- Serial No. -|-  Version -|
|------------|----------------------------------|--------------|------------|
|-     True -|-         Phidget Bridge 4-input -|-     469514 -|-      102 -|
|------------|----------------------------------|--------------|------------|
Number of bridge inputs: 4
Data Rate Max: 8
Data Rate Min: 1000
Input Value Max: 124
Input Value Min: -124
Set data rate to 8ms ...
Bridge 469514: Input 0: -0.019476
Bridge 469514: Input 1: -0.069260
Bridge 469514: Input 2: -0.052450
Bridge 469514: Input 3: 0.070930
Bridge 469514: Input 0: -0.019759
Bridge 469514: Input 1: -0.069860
Bridge 469514: Input 2: -0.053880
Bridge 469514: Input 3: 0.071050
Bridge 469514: Input 0: -0.019476
Bridge 469514: Input 1: -0.068310
```

Il semblerait que se soit la fonction BridgeData qui permette l'*affichage* des données. Mais je ne vois pas comment rendre indépendant chaque valeur. :-/
De plus je n'ai jamais utilisé les fonctions du type try: , except as...

Si vous êtes en capacité de m'aider vous me sauvez la vie