VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2910
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6555
   LinkTopic       =   "Form1"
   ScaleHeight     =   2910
   ScaleWidth      =   6555
   StartUpPosition =   3  'Windows の既定値
   Begin VB.TextBox txtPos 
      Enabled         =   0   'False
      Height          =   315
      Index           =   2
      Left            =   4620
      TabIndex        =   9
      Top             =   270
      Width           =   1725
   End
   Begin VB.TextBox txtPos 
      Enabled         =   0   'False
      Height          =   315
      Index           =   1
      Left            =   2850
      TabIndex        =   8
      Top             =   270
      Width           =   1725
   End
   Begin VB.TextBox txtPos 
      Enabled         =   0   'False
      Height          =   315
      Index           =   0
      Left            =   1080
      TabIndex        =   7
      Top             =   270
      Width           =   1725
   End
   Begin VB.Timer Timer1 
      Interval        =   1
      Left            =   5910
      Top             =   2370
   End
   Begin VB.Frame Frame1 
      Caption         =   "Force"
      Enabled         =   0   'False
      Height          =   1575
      Left            =   120
      TabIndex        =   0
      Top             =   720
      Width           =   6345
      Begin VB.TextBox txtForce 
         Height          =   300
         Index           =   0
         Left            =   4890
         TabIndex        =   3
         Text            =   "Text"
         Top             =   210
         Width           =   1335
      End
      Begin VB.TextBox txtForce 
         Height          =   300
         Index           =   1
         Left            =   4920
         TabIndex        =   2
         Text            =   "Text"
         Top             =   630
         Width           =   1335
      End
      Begin VB.TextBox txtForce 
         Height          =   300
         Index           =   2
         Left            =   4920
         TabIndex        =   1
         Text            =   "Text"
         Top             =   1050
         Width           =   1335
      End
      Begin MSComctlLib.Slider sldForce 
         Height          =   285
         Index           =   0
         Left            =   930
         TabIndex        =   4
         Top             =   240
         Width           =   3885
         _ExtentX        =   6853
         _ExtentY        =   503
         _Version        =   393216
         LargeChange     =   500
         Min             =   -3000
         Max             =   3000
         TickFrequency   =   1000
      End
      Begin MSComctlLib.Slider sldForce 
         Height          =   285
         Index           =   1
         Left            =   930
         TabIndex        =   5
         Top             =   630
         Width           =   3885
         _ExtentX        =   6853
         _ExtentY        =   503
         _Version        =   393216
         LargeChange     =   500
         Min             =   -3000
         Max             =   3000
         TickFrequency   =   1000
      End
      Begin MSComctlLib.Slider sldForce 
         Height          =   285
         Index           =   2
         Left            =   930
         TabIndex        =   6
         Top             =   1020
         Width           =   3885
         _ExtentX        =   6853
         _ExtentY        =   503
         _Version        =   393216
         LargeChange     =   500
         Min             =   -3000
         Max             =   3000
         TickFrequency   =   1000
      End
      Begin VB.Label Label4 
         Alignment       =   1  '右揃え
         Caption         =   "Z : "
         Height          =   225
         Left            =   210
         TabIndex        =   15
         Top             =   1050
         Width           =   735
      End
      Begin VB.Label Label3 
         Alignment       =   1  '右揃え
         Caption         =   "Y : "
         Height          =   225
         Left            =   210
         TabIndex        =   14
         Top             =   630
         Width           =   735
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "X : "
         Height          =   225
         Left            =   210
         TabIndex        =   13
         Top             =   270
         Width           =   735
      End
   End
   Begin MSComctlLib.Slider sldStiffness 
      Height          =   285
      Left            =   1140
      TabIndex        =   12
      Top             =   2430
      Width           =   4545
      _ExtentX        =   8017
      _ExtentY        =   503
      _Version        =   393216
      LargeChange     =   500
      Max             =   3000
      TickFrequency   =   1000
   End
   Begin VB.Label Label1 
      Caption         =   "Stiffness : "
      Height          =   225
      Left            =   240
      TabIndex        =   11
      Top             =   2460
      Width           =   885
   End
   Begin VB.Label Label 
      Caption         =   "Position : "
      Height          =   225
      Left            =   180
      TabIndex        =   10
      Top             =   330
      Width           =   885
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private m_eng As CaoEngine
Private m_ctrl As CaoController
Private m_Pos As CaoVariable
Private m_Force As CaoVariable

Private Sub Form_Load()

    Set m_eng = New CaoEngine
    Set m_ctrl = m_eng.Workspaces(0).AddController("TEST", "CaoProv.SensAble.PHANTOM")
    Set m_Pos = m_ctrl.AddVariable("CurrentPosition")
    Set m_Force = m_ctrl.AddVariable("CurrentForce")
End Sub

Private Sub Timer1_Timer()
    
    Dim Pos As Variant
    Dim dForce(2) As Double

    Pos = m_Pos.Value
    Dim i As Long
    For i = 0 To 2
        txtPos(i).Text = Pos(i)

        Dim dStiffness As Double
        dStiffness = sldStiffness.Value / 1000
        If Pos(i) > 30 Then
            dForce(i) = -dStiffness * (Pos(i) - 30)
        ElseIf Pos(i) < -30 Then
            dForce(i) = -dStiffness * (Pos(i) + 30)
        Else
            dForce(i) = 0
        End If

        sldForce(i).Value = dForce(i) * 1000
        txtForce(i).Text = dForce(i)
    Next
    
    m_Force.Value = dForce
    
End Sub
