Skip to main content

Configuring Servomotor

Requirement: An Adafruit 16-channel/12-bit PWM board is connected via I²C and a model servo is wired to its first PWM channel.

The SoftMotion Servo Example.project project contains an application where CODESYS SoftMotion is used in conjunction with model servo motors. An expansion board (Adafruit ID 815) connected via I²C is used as communication interface.

  1. Open the SoftMotion Servo Example.project project and update it.

  2. In the device tree, double-click Device.

    The device editor opens.

  3. In Communication Settings, click Scan Network.

    If your Raspberry Pi and the development system are on the same network, then your Raspberry Pi is displayed for selection.

  4. Select it and click Online → Login.

    The application is downloaded to your Raspberry Pi.

  5. Start the program (press the F5 key).

    The servo motor starts to rotate steadily from left to right. The PLC_PRG program implemented in SFC is responsible for this. It switches the axis on and then moves it between the -60 and +60 positions specified as end positions in the SM_Drive_Servo axis configuration.

    The position preset is transported via the PWM interface, as is usual with modeling servos. A HIGH pulse, which is between 1 and 2 ms long, is transmitted with a fixed frequency (default: 50 Hz; parameter of the Adafruit PWM SoftMotion device). 1 ms stands for the lower end position and 2 ms for the upper end position. The movement range varies from motor type to motor type. If the motor is controlled in angular degrees, you have to measure the movement range. To do this, drive to the end positions (in the example -60, +60) and enter the measured positions in the configuration screen:

    _rbp_projected_softmotion_servo_configuration.png
  6. Open any browser (possibly on a smartphone) and specify the address <network address>:8080/webvisu.htm.

    The visualization opens and displays the generated specified position. You can control the velocity.

    _rbp_projected_softmotion_servo_visu.png