Simulation Controller (or how to move it)
Well, I've noticed that a lot of people want to move things while running a simulation.
Here comes a handy instruction on how to do that:
SimulationController.zip
Oh, and let's see if Dean takes a look at this or not...
Developer Center
Comments
-
Thanks alot for this demonstration, and offtopic: Techsmith Camtasia is really sweet Worth every penny/dollar/euro/yen!
[edit]
Damn... those drag&drop smilies are irritating.. what about the usual etc...
[/edit]
Melk38033,8438194444<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Yupp, camtasia rules the screencams...
Well I don't find those smilies that irritating, it's an excellent way to show irony or emotions, something that usually is lost in forums.
8~)John
Developer Center0 -
Thanks for the avi John - my customer will also find this useful
Dean Thomas
ABB Support Engineer
Channel Partners Australia0 -
[quote]
Well I don't find those smilies that irritating, it's an excellent way to show irony or emotions, something that usually is lost in forums.
8~)[/quote]
John i think you might not understood what i was trying to say. It's not the smilies that are irritating. By all means i'm glad they are here. But the way you have to place one in a post is a littlebit unhandy. You have to drag & drop them from the list instead of just typing the code. But this is just my opinion.. :P
<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Ah, sorry my mistake. Yes I'd say that forums that replaces text and turns them into smilies are a neater way of doing it.John
Developer Center0 -
Hello,
I have tried to get this example working with a mechanism. I can move the mechanism, but i cannot stop it from going into the joint limits. How can i add the jointlimits and predefine on which angle (degrees) the movement should stop? I would like to add this angle into the macro. Below the code i created with your example. But i'm really bad with making macro's, so if you might have a answer.. i'd thank you greatly for a solution i could copy/paste..
Dim velocity As Integer
Private Sub Controller_AfterTick(ByVal Time As Double)
'This example moves a mechanism
'The name of the moving mechanism is: Mecha1
ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue = ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
End Sub
Private Sub Controller_Create()
velocity = -1
End SubSub startMech() 'this adds the controller to the simulation
Oscar38072,4428356482
'MechanisMove is the controller
'RobotStudio Class Object > Insert > Controller Class > Name it and declare that name here
Dim x As MechanisMove
Set x = ActiveStation.CreateController("MechanisMove")
x.Name = "JohnWiberg"
ActiveStation.Simulations("Simulation1").Controllers.Add x
End Sub
Sub stopMech() 'this kills the controller after simulation
ActiveStation.Simulations("Simulation1").Controllers("JohnWiberg").Delete
End Sub
Sub scan() 'Scan for controllers not killed
Dim x As Controller
For Each x In ActiveStation.Simulations("Simulation1").Controllers
ActiveStation.PrintLog "Log", x.Name
Next
End Sub0 -
Well, well, well. A copy/paste solution? Feeling a bit lazy?
All I did was put in checks for the lower and upper limit of the joint.
Dim velocity As Integer
Private Sub Controller_AfterTick(ByVal Time As Double)
'This example moves a mechanism
'The name of the moving mechanism is: Mecha1
If ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) > ActiveStation.Mechanisms("Mecha1").Joints(1).LowerLimit And ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) < ActiveStation.Mechanisms("Mecha1").Joints(1).UpperLimit Then
ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue = ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
End If
End Sub
Private Sub Controller_Create()
velocity = -1
End SubWith similiar code I could check for IOs and move only as long as the IO is moving etc.
Why I use a velocity value is that then I could change that value using other macros...
John
Developer Center0 -
Interesting.. i was facing similar problems with a simulation i'm trying to run right now, and Oscar i think i can help you a little towards your goal to specify an angle on which the mechanism will stop moving.
First of all i declared the velocity as a Double
Dim velocity As Double
This will allow for velocities that aren't round numbers (like 0.5 or 1.3). I use lower values. I did this because i noticed that the movement of the mechanism doesn't stop exactly at the Upper/LowerLimit when using higher velocities. I have a turntable that (with velocities above 0.5) will only reach 358 degrees in stead of 360.
I also noticed that RS uses Radiants. And I as well want to use Degrees. So i use a helper value to convert radiants into degrees (found in RS API help)
Dim Rad2Deg As Double
Rad2Deg = 1 / 360 * 2 * 4 * Atn(1)Then when specifieing a new angle use something like this:
jointValues(1) = 90 * Rad2Deg
But this is where i am stuck too. I only got this working on a robot, and it jumps from one angle to another, so no smooth movement..
The three things i'm eager to know are first, how to declare a specific rotation in degrees on which the mechanism stops moving. The mechanism I use is a turning table which can rotate from +360 to -360 degrees. I'd like to stop the movement when the turning table has turned 90 degrees (or any other angle). And i know this is possible without having to configure the turning table as an external axis.
The second question is about how to abort the macro when the desired rotation is reached. Right now i use a separate macro to stop the controller, but this doubles the amount of IO i need to use..
The third question would be about how to reach the exact angle, even when using higher velocities. Like i said before i need to drop the velocity to 0.5 or below in order to really reach the Upper/LowerLimit. And in some cases this causes long waits....
Oh and even a fourth question comes to mind... How to set an input on the robot from within the macro.. In this case i can remove the WaitTime-instructions and establish a handshake between the robot and the macro.
I know i'm asking pretty damn much.. but any efforts towards any of this goals are much appreciated.. (hmm.. deja vu.. i've said this before...)
Melk38075,9059722222<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Oh and i forgot about the code i cooked up so far (well... copied ). It's the part that i got working, so the helper value isn't included
Sub TurnTableStart()
Dim x As TurnTable
Set x = ActiveStation.CreateController("TurnTable")
x.Name = "TurnTable"
ActiveStation.Simulations("Simulation1").Controllers.Add x
End Sub
Sub TurnTableStop()
ActiveStation.Simulations("Simulation1").Controllers("TurnTable").Delete
End SubDim velocity As Double
Private Sub Controller_AfterTick(ByVal Time As Double)
If ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) > ActiveStation.Mechanisms("TurnTable").Joints(1).LowerLimit And ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) < ActiveStation.Mechanisms("TurnTable").Joints(1).UpperLimit Then
ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue = ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
End If
End Sub
Private Sub Controller_Create()
velocity = 0.5
End Sub<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
I also noticed that RS uses Radiants. And I as well want to use Degrees.
Another function you should look at is:
UnitToAPI(rsQuantityAngle,value)
This converts from whatever units the user uses to what the API is using. The reverse is APIToUnit.***Do not use this***
Dim Rad2Deg As Double
Rad2Deg = 1 / 360 * 2 * 4 * Atn(1)You said that you found this in the help? Can you tell me where so I can change it? To get a good definitation of degrees to radiants and vice versa then define it like this instead:
Dim PI As Double
PI = 4 * Atn(1)
Dim deg2rad As Double
deg2rad = PI / 180
Dim rad2deg As Double
rad2deg = 180 / PI
That is sooooooo much easier and nicer. Plus it gives an insight in how it really works as well.
(For you codecrunchers out there you should dim the constants in the Global project and the definitions in the Initialize of the Global project...)I'd like to stop the movement when the turning table has turned 90 degrees (or any other angle).
If you use my macro above then you can exchange
"ActiveStation.Mechanisms("Mecha1").Joints(1).LowerLimit"
to your lower value and
"ActiveStation.Mechanisms("Mecha1").Joints(1).UpperLimit"
to your upper value...
Now to get an exact value like a hard 90' I would actually add a check that if I'm above 90' I change it to 90' like this:
If ActiveStation.Mechanisms("Irb140_M2000").Joints(1).JointValue > 90 * deg2rad Then
ActiveStation.Mechanisms("Irb140_M2000").Joints(1).JointValue = 90 * deg2rad
End If
Now if that code would be in the 'Movement' controller class in the example above the joint could never become more that 90'.Oh, and if you like to smoothen the numbers you could do a
Round(value,5)
Which will round the value to 5 decimals. 0,00001The second question is about how to abort the macro when the desired rotation is reached.
Uhm, depends on if you want a smooth motion or a 'jump' into place?
If you are running a simulation like we are discussing here you can either set velocity=0 or you could kill the simulation controller or you could just add IF checks...
If you are running a seperate macro then an 'Exit Sub' works nicely...The third question
Same as no1 add a check that if the joint goes over the value then give it the value and stop the motion...
How to set an input on the robot from within the macro..
RTFM
Sub IOset()
Dim myIO As IO
Set myIO = ActiveMechanism.Controller.IOs("theIOname")
myIO.Value = 1
End SubJohn
Developer Center0 -
I created an example station with all code in the right places.
At Open_Station it creates its own ControllerClass to move the Mechanism 'Turner' which is in the station.
IMPORTANT!!!
Always CLOSE this station before opening a new one since I use the Station_Close event to clean up the controller.John
Developer Center0 -
Perhapse a small step for people who know how to use VBA.. but a giant step for me. Things are starting to work over here Thanx alot!
With your latest example i'm able to set/reset IO, and make my turntable stop exactly at any desired angle. Next thing i tried was to detatch the macro from the Station_Open/Close events so i could start/stop it manually, or with an OI of the robot (Private Sub Station_Open >> Sub startTurner). This seemed to work, but when i start the VC of the robot, the macro is started automatically again. And when i run the macro, in stead of trying to move the turner, the macro wants to move the robot. I'm still working on it though. I'll let you know.
<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
It all works now , there is one thing left though.. Is is possible to set an input in the macro for a given period of time (e.g. i set it to 1 and after a second it reset to 0 again)? What i mean is somewhat similar to the "PulseDO"-instruction. I now use a separate macro to reset the input with an output of the robot, but this realy fills up the event table. For me it would be a much nicer solution if the input were to reset automatically by using somesort of wait- or pulse-instruction.
<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Run the 'tester' macro below to see a use of the Time with a delay.
You could add the SetDelay in your onIOmacro and then have the IsItTime in the controller_aftertick event.Dim blTime As Boolean
Dim varTime As Variant
Sub IsItTime()
If Time >= varTime Then
ActiveStation.PrintLog "Clock", "Check: " & Time
blTime = False
End If
End Sub
Sub SetDelay(SecondsDelay As Integer)
varTime = Time + SecondsDelay / 60 / 60 / 24 'adds seconds to current time
'The unit of Time is days so to get it into seconds
'I divide by seconds/minutes/hours to get seconds/day
blTime = True
End Sub
Sub tester()
ActiveStation.PrintLog "Clock", "- - - - -"
SetDelay (3)
While blTime
ActiveStation.PrintLog "Clock", Time
IsItTime
Wend
ActiveStation.PrintLog "Clock", "- - - - -"
End SubJohn
Developer Center0 -
I'm sorry i put you to work on this.. after all it seems better not to use the delays . But it did work, and i'm trying to use it for something else. Because the station has a lot of mechanisms, i'd like to move a couple of them simultanously and then shut down their controllers with an interval. I've tried to shut down a couple of them simultanously with outputs from the robots, but that results in a crash.. So i kinda wandered whether there is a limit to the amount of active controllers<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
I haven't run into any limits on the number of controllers and I've had 30 at the same time.
So you might need to do some better cleanup...
John
Developer Center0 -
And I did .. I declared the movement of multiple mechanisms in one controller class, and that did the trick. The simulation is almost finished and my boss is already happy. Besides that, after the completion of the new workcell we're building right now, my boss will let me do the VBA coarse ...<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
-
I believe that would be the coarse in scandinavia right? I think (like always) i'm going to be visiting Zaventhem, Belgium. But basically it's the same coarse i guess..<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Hmm. I don't know about anyone but me who holds RobotStudio VBA courses...
So I think that to get it you need to travel to the beautiful city of Gothenburg in Sweden. (Flighttime Gothenburg-Brussels is about 1 hour, with pricing, if you plan ahead, as low as 100euro.Is it Ron, Luc or Peter who usually holds your courses? I could check with them if they are up to holding a VBA course but I haven't heard anything like that from them.
John
Developer Center0 -
That would be nice, i've never been to Sweden. But in that case i think i need a more tactical approach towards my boss. By now he's slowly getting used to the idea, but i'm not sure at all how he'll think about shipping me off to Sweden.. That will take some carefull manouvering..
And i think i've had courses of both Luc and Peter, but to be sure i'll have to check my certificates (will do). And Ron, would that be Ron Nakken perhapse?
<@Logan> I spent a minute looking at my own code by accident.
<Beeth> And your point is?
<@Logan> I was thinking "What the hell is this guy doing?"0 -
Right, Ron is Ron Nakken. But Dick I don't think that I've met.
Just to add a few arguments for a possible confrontation with your boss:
- You would be in the office of the developers and would therefore be able to get and give direct input if you want.
- You would have a chance to ask advanced questions not only on VBA stuff but also generic RobotStudio.
- Apart from meeting an expert teacher you would also meet other RS users who could give you new insight in how to get maximum return on the investment in offline simulation.
- If you would book it in advance we could arrange demos of other productivity increasing softwares and coming releases.
John
Developer Center0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 314 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 794 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings