Executing the commands

Let's now start sending the commands from MQTT.fx client and see our car in motion.

To move forward, we publish the message forward on topic controlPi/cmd as shown in Figure 8.12.

Command:

Figure 8.12

On the Subscribe tab we will see the message move forward as acknowledgment sent back from the car as a confirmation that the car is moving forward now. Refer to the following screenshot:

Acknowledgment:

Figure 8.13

To move backward/reverse we publish command reverse; the car will start moving in a backward direction, the red LED will glow and on the Subscribe tab we will see the message move reverse.

Command:

Figure 8.14

Acknowledgment:

Figure 8.15

To make a right turn Publish message right; the car will make a right turn and the right side indicator will blink. On the Subscribe tab we will receive the message Turn Right.

Command:

Figure 8.16

Acknowledgment:

Figure 8.17

To make a left turn Publish the message left; the car will make a the left turn and left side indicator will blink. On the Subscribe tab we will receive the message Turn Left.

Command:

Figure 8.18

Acknowledgment:

Figure 8.19

The resolution of the PWM signal is 255 by default which indicates that to run the motor at maximum speed, duty cycle of the PWM signal will need to be set at 255 that is the signal will remain high throughout.

To change the speed of the car we will modify the value of the duty cycle. Please note that value of duty cycle should not go beyond the maximum resolution of the PWM signal which is 255 in our case:

  • If we publish message as 64, car will move at 1/4 of top speed
  • If message is 128, car will move at 1/2 of top speed
  • If message is 192, car will move at 3/4 of top speed
  • And when message is 255, car will move at top speed

Command:

Figure 8.20

Acknowledgment:

Figure 8.21
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.95.38