13.4 Controlling a motor

Problem

Solution

Since HARK itself is software for audition processing, a module describing the control of a motor is not included. However, when performing comparatively simple control, a module can be designed to control a motor. This section describes how a method of implementing this function in the client part of HARK as a module by dividing control of a motor into applications of server and client. The following is an example of the main processing of the client module.

function calculat

  1. if count = 0 then

  2. set_IP_address_and_PORT_number

  3. connect_to_server

  4. endif

  5. obtain_input

  6. generate_control_input

  7. send_control_input

  8. check_motor_state

function destructor
  1. disconnect_to_server

The first calculate function performs processing related to TCP/IP connection once when it is first activated and repeats the processing for other cases. To access TCP/IP, the first activation of this function sets the assigned IP address port and connects to the server application (the second and third lines). When it is first connected to the server application, it repeats processing to generate a control command from an input. After an input is received, a command for motor control is created based on the data. This command is sent to the server application, which confirms whether the command was sent properly. The second destructor function indicates a destructor of a module and performs processing to cut off connections with the server. The server application receives a control command from the client module and drives the motor based on the command. This server application depends on motors and its description is therefore omitted here.

Discussion

Since Flowdesigner is data flow-oriented, the presence of even one node that requires a long time for processing, makes real-time processing difficult in some cases. Therefore, processing on Flowdesigner consists of generating a command to control a motor, with the load reduced by operating the motor in other server applications. Moreover, dividing into a server and a client enables another motor to be controlled simply by changing the interface.

See Also

For motor control, see “Creation of node” in 12.1. For the combined control of a more complicated motor or other sensors, see “Control of robot” in 12.2.