Tick problem

Hi, I’m trying to use the tick system but it’s getting me crazy. I just want show every second a message in the log when simulation is running, to know how the ticks work.

Also I’ve tried to run this example from the robotstudio help, getting the same results: nothing.

Thanks!

'In TheRoborStudioProject
Dim WithEvents sim As Simulation

Sub InitBoxCtrl()

Set sim = ActiveStation.Simulations(1)

'Set the resoluition of the Simulation to 0.5 seconds
'The simulation will generate a Tick event every 0.5 seconds
sim.Resolution = 0.5

’ Create and add a contoller to the simulation
Dim BoxCtrl As BoxController
Set BoxCtrl = ActiveStation.CreateController(“BoxController”)
Call sim.Controllers.Add(BoxCtrl)
BoxCtrl.IOs.Add

'Start the simulation
sim.Start

End Sub

Sub sim_Tick()
'For instance do collision detection
End Sub

'** This is the Controller class called BoxController, used above

Dim myPart As part
Dim speed As Double

Private Sub Controller_AfterTick(ByVal Time As Double)
myPart.Transform.x = Time * speed
myPart.Entities(1).Color = Array(Int(Time * 100) Mod 255, Int(Time * 200) Mod 255, Int(Time * 300) Mod 255)
End Sub

Private Sub Controller_BeforeTick(ByVal Time As Double, MaxTime As Double)

'Do test if possible to have stepsize Time otherwise
'return max step size in MaxTime
End Sub

Private Sub Controller_Create()
'Called when a controller instance is created
Set myPart = ActiveStation.Parts.Add
Call myPart.CreateSolidBox(New Transform, 0.2, 0.3, 0.4)
End Sub

Private Sub Controller_Start()
speed = 0.5
End Sub

Private Sub Controller_Stop()
'Do tidying up
End Sub

Hi
The way to do this is to insert a controller class (in VBA menu insertcontroller class)

Name it “myController”

The open up the code window for that controller class and select the After_Tick event and add your code.
Example:
Private Sub Controller_AfterTick(ByVal Time As Double)
ActiveStation.PrintLog “Time”, CStr(Time)
End Sub

Then open the code window for this station and add following

Dim m_controller As Controller
Sub Start()
Set m_controller = ActiveStation.CreateController(“myController”)
ActiveStation.Simulations(1).Controllers.Add m_controller
End Sub

Then execute the Start sub and after that press play in RS.
The controller class should write the time to the log window every tick.

Hint
To be able to see what simulations and controllers you have in RS uncheck prune subtree in menu
SettingsBrowser settingsPrune subtree

You will now have more information visible in the browser.

Thanks for your fast repply, I was suspecting that the problem came this way… but the next problem is: What I must do to change the name of a “controller class”?:grinning:

And regarding your hint, You were referring to the Robotstudio Window or the VBA window?, sorry, I can’t find it.

Thanks!

Hi

To change the name of a controller class just select the class and change the name in the property browser. (VBA Window)

The hint refer to the RS Window menu View (sorry forgott View)

Thanks for your time, your replies was very usefull for me.

See you!

Alfredo