3 Replies Latest reply on Jan 16, 2018 4:13 PM by hshintani RSS
    hshintani Newbie

    How to control motor speed with ThingWorx

    Now,i try to control speed of motor with temperature sensor and ThingWorx.

    I attempt pictures which explains this thing.

    Is it possible to control motor speed by entering the script of motor_control in the space of subscriptions of the Thing's Entity Information like second picture?

    If anyone knows information about this,please let me know something.


      • Re: How to control motor speed with ThingWorx
        ianban Creator



        I recently modified a Lego Technics Excavator so that it was controlled via ThingWorx and a Raspberry Pi rather than the Infra Red controller it comes with. I used the Java SDK to write the "agent" on the Pi. The Pi had a motor controller hat (from AdaFruit) on it.  I had to write java code to create some methods within the Agent to control the motors, the hat uses Pulse Width Modulation to control motor speed writing Java to control this was a pain! By varying the values you use it is possible to control the motor speed with quite a range of speeds available. As the Excavator only needs motors to be on forwards, on backwards and off. I always run them at full speed.

        So, short answer is yes. The bigger question is what hardware/software combination are you using to control the motor? You need to write code methods that control your motor - make sure these work outside of ThingWorx. Wrap these methods in ThingWorx Services as part of your agent. Then when your device connects, bring these services into the model definition (Services page, Browse Remote services button) once you have the service(s) there you can call them like any other ThingWorx service. Don't forget to have a subscription to turn the motor off when the temperature drops.

        Remote services are very powerful and surprisingly quick in operation.



          • Re: How to control motor speed with ThingWorx
            hshintani Newbie



            Thank you for the information.

            I use BrickPi for connecting Motor and RaspberryPi.And,the motor is LEGO parts of Mindstorms.

            So,the code methods which controls motor_speed is Python.The contents of command is that

            if temperature > 28:

              BrickPi.MotorSpeed[PORT] = 0.

            Should I write this code with Java and input this command in the space of Service Definition?


            iot is very interesting and difficult....




            Hideyuki Shintani

              • Re: How to control motor speed with ThingWorx
                laurentger Apprentice

                I did something similar with the TW  java SDK on a galileo board with a stepper motor.( similar to that one http://www.instructables.com/id/BYJ48-Stepper-Motor/)


                1/ Create java methods to control motor rotation forward or backward i have 2 arguments ( angle, speed)

                2/ Bind those methods as remote services

                      @ThingworxServiceDefinition( name="avanceMoteur", description="Forward engine by x degrees")

                     public   void avanceMoteur (  @ThingworxServiceParameter( name="angle", description="rotation angle", baseType="NUMBER" ) Double  angle,       @ThingworxServiceParameter( name="speed", desc

                3/ Write logic either as event/subsciption as you sugestted  ( i recommend using a timer every x minutes instead  of a property changed event, so that you leave enough time for the motor to reacdh the desired position) , or in a mashup ( ie in the example below,  the motor control a mobile curtain ( up or down) that can be moved based on light and temp sensors to lower ambiant light)