Skip to main content
1-Visitor
May 24, 2019
Solved

Continuous Rotation of fan

  • May 24, 2019
  • 2 replies
  • 3921 views

Hello,

 

I am working on fan model where I just want to rotate the fan blades continuously and not its outer cover until I click on stop button. So, can anyone suggest any solution for the same? 

Best answer by ClayHelberg

It might be easier to do this entirely in Javascript instead of using a sequence that gets repeated. First, you'll need to make a modelItem corresponding to the fan blade separate from the housing or any other assembly components that you don't want to spin. Suppose that modelItem is "modelItem-1". Then you could use code something like this:

$scope.fanInterval = null;

$scope.startFan = function() {
 var fanStep = 20; // adjust this to control fan speed
 $scope.fanInterval=$interval(function() {
 // you might need to replace "rx" below with "ry" or "rz" depending on
 // how your CAD model is oriented
 $scope.setWidgetProp("modelItem-1", "rx", parseInt($scope.view.wdg["modelItem-1"]["rx"]) + fanStep);
 }, 10);
}

$scope.stopFan = function() {
 $interval.cancel($scope.fanInterval);
}

Then attach your startFan() and stopFan() functions to whatever buttons, event listeners, etc. you want in order to control the fan.

2 replies

17-Peridot
May 24, 2019

Hello,

 

I will do a similar javascript code as described in this thread :

https://community.ptc.com/t5/Studio/How-to-play-all-the-Sequences-pvi-one-by-one-on-a-single-click/m-p/525857?advanced=false&collapse_discussion=true&filter=location&location=forum-board:studio&q=sequence%20timeout&search_type=thread

 

For example for a sequence selected in a Model named model1 :

$scope.runfansequence = function() { 
 setTimeout(function() {
 // Run sequence
 angular.element(document.getElementById('model1')).scope().playAll();
 // in 1000s when sequence is ending, play again the same sequence
 setTimeout(function() {$scope.runfansequence(); }, 1000);
 }, 10000); // Time to play this sequence
}

// Run first fan sequence
$scope.runfansequence();

 

Best regards,

Samuel

1-Visitor
May 28, 2019

Thank you so much for the solution Sdidier. It is working but after one rotation it stops for a second and then again starts rotate. So that because of one second stop, if feels like animation have some problem. So, kindly share any solution for the same if you have.

 

Appreciate your positive response.

18-Opal
May 24, 2019

It might be easier to do this entirely in Javascript instead of using a sequence that gets repeated. First, you'll need to make a modelItem corresponding to the fan blade separate from the housing or any other assembly components that you don't want to spin. Suppose that modelItem is "modelItem-1". Then you could use code something like this:

$scope.fanInterval = null;

$scope.startFan = function() {
 var fanStep = 20; // adjust this to control fan speed
 $scope.fanInterval=$interval(function() {
 // you might need to replace "rx" below with "ry" or "rz" depending on
 // how your CAD model is oriented
 $scope.setWidgetProp("modelItem-1", "rx", parseInt($scope.view.wdg["modelItem-1"]["rx"]) + fanStep);
 }, 10);
}

$scope.stopFan = function() {
 $interval.cancel($scope.fanInterval);
}

Then attach your startFan() and stopFan() functions to whatever buttons, event listeners, etc. you want in order to control the fan.

1-Visitor
May 27, 2019

Hi Clay,

 

Stopfan() function isn't working for me.

Do you have idea on how to rotate a modelitem based on input from thingworx composer. i.e i need a spindal to rotate in accordance with rpm property value from one of 'thing' in composer 

18-Opal
May 28, 2019

Check your call to stopFan(). Make sure to match case exactly--it's stopFan(), not Stopfan(). It worked in my quick test. If it's not a spelling/case issue, try using the browser debugger to troubleshoot it.

 

If you want the rotation to be proportional to some value from Thingworx, you should be able to set that up. Add your Thingworx data as an external parameter in the usual way, and bind it to an app parameter. Then you can use a calculation to adjust the size of rotation between 'ticks' in the rotation animation based on the parameter. Your function would then look something like this:

$scope.startFan = function() {
 $scope.fanInterval=$interval(function() {
 // you might need to replace "rx" below with "ry" or "rz" depending on
 // how your CAD model is oriented
 // fan speed based on RPM app param; 1RPM = 6 degrees per second
var fanStep = parseFloat($scope.app.params['rpm']) * 0.06 ;
$scope.setWidgetProp("modelItem-1", "rx", parseInt($scope.view.wdg["modelItem-1"]["rx"]) + fanStep); }, 10); }

Notice the definition of fanStep is moved inside the interval function so that it will pick up new values of RPM as it changes.