cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous Rotation of fan

SOLVED
Highlighted
Visitor

Continuous Rotation of fan

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Continuous Rotation of fan

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.

View solution in original post

8 REPLIES 8

Re: Continuous Rotation of fan

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...

 

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

Highlighted

Re: Continuous Rotation of fan

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.

View solution in original post

Highlighted

Re: Continuous Rotation of fan

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 

Highlighted

Re: Continuous Rotation of fan

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.

Highlighted

Re: Continuous Rotation of fan

Thank you so much Clay. It is working fine but need to rotate only fan and not cover and whole model and also I can't remove the cover. So, any other method is there then kindly share.

Highlighted

Re: Continuous Rotation of fan

u can drag and drop modelitem on only fan and add script this script with modelitem number of that respective model. so that cover and whole model wont rotate 

Highlighted

Re: Continuous Rotation of fan

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.

Highlighted

Re: Continuous Rotation of fan

Thanks a lot clay
it worked 
and sorry about stopfan issue 
i did some spell mistake .

Announcements
Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection