Bonjour a tous,
j'exploite différentes cartes d'interface pc grâce a autoit et la je bloque sur un gyroscope:
les cartes on (en plus des fonctions normales) un mode évènement.
Voici un exemple que je maitrise :
la doc de la dll .com dit :
► Afficher le texte
Events
OnPositionChange
Fired when the position of a motor changes.
event OnPositionChange(
Index as Long,
Position as Double
)
Parameters:
Index
The motor index.
Position
The motor position.
pour l'exploiter j' insert dans mon script la fonction :
► Afficher le texte
Code : Tout sélectionner
Func phid1_OnPositionChange($Index, $Position_Value)
GUICtrlSetData($Input1, $Position_Value)
EndFunc
mais la je suis sur une structure en tableau que je ne parviens pas a assimiler donc je n'arrive pas a en sortir des valeurs, la doc dit :
► Afficher le texte
Structures
PhidgetSpatial_SpatialEventData
Used for the OnSpatialData event. This structure represents all the state of a PhidgetSpatial at a
moment in time.
struct PhidgetSpatial_SpatialEventData
{
double acceleration[3];
double angularRate[3];
double magneticField[3];
long time_seconds;
long time_microseconds;
}
je ne parviens pas a mi retrouver dans le tableau...
Pour exploiter les trois axe du gyro, il faut en plus appliquer une fonction sur certaines des valeurs contenue dans le tableau!!
j'ai un example en vb :
► Afficher le texte
Code : Tout sélectionner
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim WithEvents spatial As PhidgetSpatial
Attribute spatial.VB_VarHelpID = -1
Dim XFilt(6), YFilt(6), RFilt(6) As Double
Dim XOut, YOut, ROut As Double
Dim X1Old, Y1Old As Integer
Dim XCenter, YCenter As Integer
Dim lastMsCount(3) As Double
Dim gyroHeading(3) As Double
Dim lastMsCountGood(3) As Boolean
Dim compassBearing As Double
Dim lastBearing As Double
Dim compassBearingFilterSize As Integer
Dim compassBearingFilter As New Collection
Dim pi As Double
Private Sub spatial_OnSpatialData(data() As Phidget21COMCtl.PhidgetSpatial_SpatialEventData, ByVal dataCount As Long)
If spatial.GyroAxisCount > 0 Then
calculateGyroHeading data, dataCount, 0
calculateGyroHeading data, dataCount, 1
calculateGyroHeading data, dataCount, 2
gyroX.Text = FormatNumber(gyroHeading(0), 3, vbTrue, vbFalse, vbFalse) + "°"
gyroY.Text = FormatNumber(gyroHeading(1), 3, vbTrue, vbFalse, vbFalse) + "°"
gyroZ.Text = FormatNumber(gyroHeading(2), 3, vbTrue, vbFalse, vbFalse) + "°"
End If
End If
End Sub
____________________________________________________________________
Private Sub calculateGyroHeading(data() As Phidget21COMCtl.PhidgetSpatial_SpatialEventData, dataCount As Long, index As Integer)
Dim gyro As Double
Dim timeChange As Double
Dim timeChangeSeconds As Double
Dim I As Integer
gyro = 0
For I = 0 To (dataCount - 1)
gyro = data(I).angularRate(index)
If lastMsCountGood(index) Then
timeChange = (data(I).time_seconds * 1000) + (data(I).time_microseconds / 1000) - lastMsCount(index)
timeChangeSeconds = timeChange / 1000
gyroHeading(index) = gyroHeading(index) + (timeChangeSeconds * gyro)
End If
lastMsCount(index) = (data(I).time_seconds * 1000) + (data(I).time_microseconds / 1000)
lastMsCountGood(index) = True
Next I
End Sub
_______________________________________________________________________________
Que je n'arrive pas a transposer sous Autoit, parce que je ne comprend pas la structure du début...
Je suis pas très sur de mettre bien expliquer, si vous voulez la doc de la carte ou figure toutes les fonctions :
http://www.phidgets.com/documentation/Phidgets/1056.pdf
la carte possède une boussole magnétique un gyroscope 3 axes et un accéléromètre 3 axes, mais pour l'instant je ne m'interresse qu'au gyro.
Ha oui petit détail je parviens a obtenir les valeurs en temps réel des 3 axes (X,Y,Z) mais sans appliquer la fonction de calcule (comme dans l'exemple VB) elles retombes a zero dés que le gyro ne bouge plus:
► Afficher le texte
Code : Tout sélectionner
Func control()
$ang_rate_x = $oPhidget.AngularRate(0)
GUICtrlSetData($Input1,$ang_rate_x)
$ang_rate_y = $oPhidget.AngularRate(1)
GUICtrlSetData($Input2,$ang_rate_y)
$ang_rate_z = $oPhidget.AngularRate(2)
GUICtrlSetData($Input3,$ang_rate_z)
EndFunc
Voila!! un peu lourd...je sais
UN petit coup de main pour exploiter la structure et je suis sur que je me débrouillerais pour le reste...ou pas
