Deprecated: Required parameter $query follows optional parameter $post in /var/www/html/wp-content/plugins/elementor-extras/modules/breadcrumbs/widgets/breadcrumbs.php on line 1215
Set PID Line Following Parameter - PictoBlox Block | Quarky Advance Line Following
Table of Contents
[BlocksExtension]

Warning: Undefined array key "pp_wrapper_link" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/wrapper-link.php on line 194

Warning: Undefined array key "pp_wrapper_link_enable" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/wrapper-link.php on line 196

Warning: Undefined array key "pp_custom_cursor_icon" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 350

Warning: Undefined array key "pp_custom_cursor_text" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 351

Warning: Undefined array key "pp_custom_cursor_target" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 352

Warning: Undefined array key "pp_custom_cursor_css_selector" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 353

Warning: Undefined array key "pp_custom_cursor_enable" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 355

Set PID Line Following Parameter

Description

Proportional, Integral, and Derivative (PID) functions are used to improve the feedback (analog inputs from the IR Sensors) to improve the robot’s movement.

1. Proportional (P) :  
This component enables the robot to make immediate, precise adjustments based on its distance from the line. If the robot drifts too far to the right, it will steer left, and if it veers too far to the left, it will steer right to correct its course.

2. Integral (I) : 
The integral component monitors how long the robot has been off the line. If the deviation persists for an extended time, this part applies a larger correction to bring the robot back on track more effectively.

3. Derivative (D) :
The derivative component anticipates future errors by analyzing the rate at which the robot drifts from the line. This ensures smooth, predictive adjustments, helping to prevent overshooting and maintain stability.

The control output is given by:
Control Output = Proportional + Integral + Derivative

So, the PID controller combines these three components to continuously adjust the robot’s movements, keeping it as close to the line as possible while moving smoothly and fast. A robot is always learning and fine-tuning its path to stay on track.
Think of it as a smart system that balances and corrects itself as it moves, ensuring it follows the line accurately. PID line followers are commonly used in robotics competitions and educational settings to teach about control systems and automation.

Note: If you initialize a Three IR line following, use Kp (propositional constant) >= 7 for a better result.

How does PID work in the Quarky Line Following?
In Quarky’s “Do Line Following” Block/Python function, the system employs its two Infrared (IR) sensors, one on the left and another on the right, to navigate along a line.
Let’s say the analog values registered by these sensors
on a white surface are
Left = 150
Right = 170

while on the black line, they read
Left = 820
Right = 750.

When the robot is shifted to the right, the left sensor is on the black line and the right one is on the white. At this point the reading of IR Sensors is
Left =  820
Right = 170,
The error is calculated as follows:

Error = (Left Sensor Value – Right Sensor Value)/10
= (820 – 170)/10
= 65

Proportional Only
For the PID (Proportional-Integral-Derivative) controller, the constants are set as follows:
Kp = 0.5, Ki = 0, and  Kd = 0.

The proportional term is then calculated.
Proportional = K_p *Error
= 0.5* 65
= 32 (approximately)

The control output is given by:
Control Output = Proportional + Integral + Derivative

In this case, both the integral and derivative terms are set to 0, so the control output simplifies to:
Control Output = 32 + 0 + 0
= 32

Subsequently, the motor speeds are adjusted based on the control output and the motor speed parameters.

Assuming base speed = 40, minimum speed = 0, and maximum speed = 80
The Left and Right motor speeds are computed as follows:

Left Motor Speed = Base Speed – Control Output
= 40 – 32
= 8

Right Motor Speed = Base Speed + Control Output
= 40 + 32
= 72

Proportional and Integral only
The integral term in the PID (Proportional-Integral-Derivative) controller addresses the accumulated past errors over time. If there has been a persistent error over time, the integral term gradually increases, helping to eliminate the accumulated error.

In a scenario where the robot is stuck and the robot’s tires are slipping due to the excessive weight of the robot and low battery, both sensors are placed on contrasting surfaces – the Left sensor on black and the Right sensor on white. Despite the challenging conditions, the proportional constant (Kp) comes into play, initially adjusting the motor speeds. As a result, the Left motor speed becomes 8, and the Right motor speed reaches 72.

When an integral term with a constant value (Ki = 0.01) is introduced into the control equation, the integral value is updated in each iteration:

I = I + error
I = 0 + 65 = 65

The control output, comprising proportional, integral, and derivative terms, is then computed as follows:
Control Output  = Proportional +Integral + Derivative
= (0.5 * 65) + (0.01 * 65) + 0
= 32.65
Left Motor Speed = 7.35
Right Motor Speed = 72.65

In the subsequent loop, the integral term is updated again:
I = I + error
I = 65 + 65 = 130

And the control output in the next iteration becomes:
Control Output = (0.5 * 65) + (0.01 * 130) + 0
= 33.3
Left Motor Speed = 6.7
Right Motor Speed = 73.3

Proportional, Integral, and Derivative
Derivative (D): The derivative term in the PID (Proportional-Integral-Derivative) controller anticipates future errors by assessing how fast the error is changing. It plays a crucial role in preventing overshooting or oscillations by slowing down the control action as the system approaches the setpoint.

In a small arena, when a robot needs to execute a significant turn or a U-turn, increasing the proportional constant (Kp) may result in excessive oscillations. To address this, the derivative term is introduced to control oscillations and overshooting.

Consider a scenario where the error is increased:
Error = (Left Sensor Value – Right Sensor Value)/10
=(930 – 170)/10
= 76

The derivative term is computed as:
D = Previous Error – Error
= 65 – 76
= -11

The control output, including proportional, integral, and derivative terms, is then calculated as follows:
Kp = 0.5, Ki = 0.01, and  Kd = 0.2

Control Output = Proportional + Integral + Derivative
= (0.5 * 76) + (0.01 * 76) + (0.2 * -11)
= 38 + 0.76 – 2.2 = 36.56

Subsequently, the left and right motor speeds are adjusted:
Left Motor Speed = 3.44
Right Motor Speed = 76.56

In the subsequent loop, the integral term is updated, and the process repeats with a new error:
Error =  (600 – 170)/10
= 43

The integral term is updated:
I = I + Error
= 76 + 43
= 109

The derivative term for the new error is computed:
D = Previous Error – Error
= 76 – 43
= 33

The control output remains the same in this loop:
Control Output  = (0.5 * 43) + (0.01 * 109) + (0.2 * 33)
= 21.5 + 1.09 + 6.6
=29.19

Left Motor Speed = 10.81
Right Motor Speed = 69.19

This iterative process continues, with the derivative term helping to manage the robot’s response to changing errors, ultimately enhancing its stability.

 

Example

The example demonstrates using the Quarky touch display to make touch piano.

Script

 

Output

Touch-Numbers

Read More
The example demonstrates how to run different actions with the Quarky touch sensor to make a disco party in PictoBlox.

Script

Output

Read More
The example demonstrates how to use an ultrasonic sensor with Quarky.

Connections

Now we will connect the Ultrasonic Sensor to the Robot. The sensor and the robot have the following pins:

  1. Ultrasonic Sensor Pins:
    1.  VCC
    2. GND
    3. Trig
    4. Echo
  2. Quarky Pins:
    1. GND
    2. V
    3. D1
    4. D2

We will start with connecting the ultrasonic sensor with Quarky using the 4 set wire provided in the kit. But, first, make the connection in the following way:

  • First, connect the VCC of the ultrasonic sensor with the V pin on the Quarky.
  • Connect the GND of the ultrasonic sensor with the Ground pin on the Quarky.
  • Connect Trig of the ultrasonic sensor with D1 pin on the Quarky.
  • Finally, connect the Echo of the ultrasonic sensor with the D2 pin on the Quarky.

Script

Output

Read More
The example demonstrates how to make the sprite movement with Quarky buttons.

Code

sprite = Sprite('Tobi')
quarky=Quarky()

while True:
  if quarky.readpushbutton("L"):
    sprite.move(-10)
  elif quarky.readpushbutton("R"):
    sprite.move(10)

Output

Read More
The example demonstrates using the Quarky touch display to make a touch piano in the Python Coding Mode.

Code

sprite = Sprite('Tobi')
quarky = Quarky()

while True:
  if quarky.ispadtouched("T1"):
    quarky.drawpattern("bbbjjbjjbjjbbjjbjjjbjjbjjjbjjbjjbbb")
    quarky.playtone("C4", 8)

  if quarky.ispadtouched("T2"):
    quarky.drawpattern("cccjcccjcjjjjcjcjjcccjcjjcjjjcjjccc")
    quarky.playtone("D4", 8)

  if quarky.ispadtouched("T3"):
    quarky.drawpattern("fffjfffjfjjjjfjfjjfffjfjjjjfjfjjfff")
    quarky.playtone("E4", 8)

  if quarky.ispadtouched("T4"):
    quarky.drawpattern("dddjdjdjdjjdjdjdjjdddjdjjjjdjdjjjjd")
    quarky.playtone("F4", 8)

  if quarky.ispadtouched("T5"):
    quarky.drawpattern("gggjgggjgjjgjjjgjjgggjgjjjjgjgjjggg")
    quarky.playtone("G4", 8)

Output

Read More
The example demonstrates how to use an ultrasonic sensor with Quarky.

Connections

Now we will connect the Ultrasonic Sensor to the Robot. The sensor and the robot have the following pins:

We will start with connecting the ultrasonic sensor with Quarky using the 4 set wire provided in the kit. But, first, make the connection in the following way:

  • First, connect the VCC of the ultrasonic sensor with the V pin on the Quarky.
  • Connect the GND of the ultrasonic sensor with the Ground pin on the Quarky.
  • Connect Trig of the ultrasonic sensor with D1 pin on the Quarky.
  • Finally, connect the Echo of the ultrasonic sensor with the D2 pin on the Quarky.

Code

sprite = Sprite('Tobi')
quarky = Quarky()

quarky.setultrasonicpins(1, 18, 19)
while True:
  sprite.say(quarky.getdistance(1))

 

Output

Read More
The example demonstrates how to run different actions with the Quarky touch sensor to make a disco party in Python Coding Environment.

Code

sprite = Sprite('Cassy Dance')
quarky = Quarky()

import time

sprite.switchcostume('cassy-a')
sprite.gotoxy(0, 0)

while True:
  if quarky.ispadtouched("T1"):
    quarky.playsound("QuarkyIntro")

  if quarky.ispadtouched("T2"):
    quarky.showpattern("party colors")

  if quarky.ispadtouched("T3"):
    time.sleep(0.2)
    sprite.nextcostume()

  if quarky.ispadtouched("T4"):
    quarky.stopaudio()

Output

Read More
A waste management system that will differentiate the waste based on its type. If it detects biodegradable waste, the LEDs Quarky’s matrix will turn green. If it’s non-biodegradable waste, the LEDs will turn blue.

Script

Output

Read More
The example demonstrates how to run an object detection on the stage and show all the objects with confidence.

Script

Output

  1. Detection at 0.3
  2. Detection at 0.5
  3. Detection at 0.8
Read More
The example demonstrates how to detect persons on the stage with different confidence thresholds.

Script

Output

Read More
waste
A waste management system that will differentiate the waste based on its type in Python Coding Environment. If it detects biodegradable waste, the LEDs Quarky’s matrix will turn green. If it’s non-biodegradable waste, the LEDs will turn blue.

Code

sprite = Sprite('Tobi')
od = ObjectDetection()
speech = TexttoSpeech()
quarky = Quarky()

od.video("on", 1)
od.enablebox()
od.setthreshold(0.5)

speech.setvoice('alto')
speech.setlanguage('en')

while True:
  od.analysecamera()
  
  if od.isdetected('banana'):
    quarky.drawpattern("ccccccccccccccccccccccccccccccccccc")
    speech.speak("Biodegradable Waste")
  
  if od.isdetected('bottle'):
    quarky.drawpattern("fffffffffffffffffffffffffffffffffff")
    speech.speak("Non Biodegradable Waste")

Output

waste

Read More
The example demonstrates how to run an object detection on the stage and show all the objects with confidence.

Code

sprite = Sprite('Square Box')
obj = ObjectDetection()

obj.disablebox()
obj.setthreshold(0.5)
obj.analysestage()

sprite.gotoxy(0, 0)
sprite.setsize(100)
sprite.say(str(obj.count()) + " Object Detected", 2)

for object in range(1, obj.count() + 1):
  sprite.setx(obj.x(object))
  sprite.sety(obj.y(object))
  sprite.setsize(obj.width(object))
  sprite.say(obj.classname(object) + " with " + str(obj.confidence(object)), 2)

Output

  1. Detection at 0.3
  2. Detection at 0.5
  3. Detection at 0.8
Read More
The example demonstrates how to detect persons on the stage with different confidence thresholds.

Code

sprite = Sprite('Tobi')
obj = ObjectDetection()

obj.enablebox()
sprite.gotoxy(-180, -110)
sprite.setsize(100)

obj.setthreshold(0.3)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.3 Threshold", 2)

obj.setthreshold(0.5)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.5 Threshold", 2)

obj.setthreshold(0.9)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.9 Threshold", 2)

Output

Read More
The examples show how to use Pose Recognition in PictoBlox to count the number of body parts detected in the body.

Script

Output

Read More
The example demonstrates how to use hand recognition and pen extensions to make an air draw game.

Script

Output

Read More
The example demonstrates how to use hand recognition to track the different parts of the fingers.

Script

Output

Read More
The example demonstrates how to use human body detection to track the nose and make someone clown.

Script

Output

Read More
The example demonstrates how to use hand recognition to track the different parts of the fingers in Python Coding Environment.

Code

thumb = Sprite('Thumb')
index = Sprite('Index')
middle = Sprite('Middle')
ring = Sprite('Ring')
pinky = Sprite('Pinky')

hand = Posenet()
hand.video("on", 0)
hand.enablebox()

thumb.switchcostume("ball-a")
thumb.setsize(50)
index.switchcostume("ball-b")
index.setsize(50)
middle.switchcostume("ball-c")
middle.setsize(50)
ring.switchcostume("ball-d")
ring.setsize(50)
pinky.switchcostume("ball-e")
pinky.setsize(50)

while True:
  hand.analysehand()
  
  if hand.ishanddetected():
    thumb.setx(hand.gethandposition(1, 4))
    thumb.sety(hand.gethandposition(2, 4))
    thumb.show()
    
    index.setx(hand.gethandposition(1, 8))
    index.sety(hand.gethandposition(2, 8))
    index.show()
    
    middle.setx(hand.gethandposition(1, 12))
    middle.sety(hand.gethandposition(2, 12))
    middle.show()
    
    ring.setx(hand.gethandposition(1, 16))
    ring.sety(hand.gethandposition(2, 16))
    ring.show()
    
    pinky.setx(hand.gethandposition(1, 20))
    pinky.sety(hand.gethandposition(2, 20))
    pinky.show()
  
  else:
    thumb.hide()
    index.hide()
    middle.hide()
    ring.hide()
    pinky.hide()

Output

Read More
The examples show how to use Pose Recognition in PictoBlox to count the number of body parts detected in the body in Python Coding Environment.

Code

sprite = Sprite('Tobi')
pose = Posenet()

pose.video("on", 0)
pose.enablebox()

while True:
  pose.analysecamera()
  bodyPartCount = 0
  
  for i in range(21):
    if pose.isdetected(i, 1):
      bodyPartCount += 1
  
  sprite.say(str(bodyPartCount) + " Parts Detected")

Output

Read More
The example demonstrates how to use human body detection to track the nose and make someone clown.

Code

sprite = Sprite('Ball')
pose = Posenet()

pose.video("on", 0)
pose.enablebox()

while True:
  pose.analysestage()
  
  if (pose.isdetected(0, 1)):
    sprite.setx(pose.x(0, 1))
    sprite.sety(pose.y(0, 1))
    sprite.show()
  
  else:
    sprite.hide()

Output

Read More
The example demonstrates how to use hand recognition and pen extensions to make an air draw game in the Python Coding Environment.

Code

sprite = Sprite('Pencil')

hand = Posenet()
pen = Pen()

hand.video("on", 0)
hand.disablebox()

pen.clear()
pen.setcolor([0, 255, 0])
pen.setsize(2)

while True:
  hand.analysehand()
  if hand.ishanddetected():
    if sprite.iskeypressed("space"):
      pen.down()
      sprite.setx(hand.gethandposition(1, 8))
      sprite.sety(hand.gethandposition(2, 8))
    else:
      pen.up()

Output

Read More
The example demonstrates how to use sign detection and make the Quarky show the detection on the LED.

Script

Output

Read More
The example demonstrates how to implement sign detection in PictoBlox.

Script

Output

Read More
The example demonstrates how to find the closest sign from multiple sign detection and make the decision accordingly.

Script

Output

Read More
The example demonstrates how to make an object-tracking robot.

Script

Output

Read More
Speech Recognition
The example demonstrates how to make smart home automation for light control using NLP and Speech Recognition.

Script

Output

Read More
The example demonstrates how to make a QR Code reader.

Script

Output

Read More
The example demonstrates how to make a QR Code reader in the Python Coding Environment.

Code

sprite = Sprite('Square Box')
qr = QRCodeScanner()

qr.video("on flipped", 0)
qr.disablebox()

while True:
  qr.analysecamera()
  if qr.isdetected():
    sprite.setx(qr.xpos("center"))
    sprite.sety(qr.ypos("center"))
    sprite.setdirection(qr.angle())
    sprite.say(qr.codedata())
    sprite.show()
  else:
    sprite.hide()

Output

Read More
The example demonstrates how to make a sprite be fixed to a point but can rotate. The wand is hanging like a pendulum.

The example demonstrates how to make a sprite be fixed to a point but can rotate. The wand is hanging like a pendulum.

The center of the wand in the costume is the point of rotation.

The following code creates the simulation of the pendulum.

Output

Read More
In this example, you understand the effect of the density, roughness, and bounce properties of the sprites. The ball falls from the top randomly, and the bell is fixed but can rotate. 

In this example, you understand the effect of the density, roughness, and bounce properties of the sprites. The ball falls from the top randomly, and the bell is fixed but can rotate.

Script of Bell

The bell center is changed to make it swing from the top.

Script for Ball

This script creates clones of the ball every 0.5 seconds.

This script assigns the properties of the clone.

Output

We will change the density of the bell and the ball in the block – set sprite density () roughness () bounce (). This will result in different simulations.

  1. Bell is very light and the balls are very heavy: The inertia of the balls will affect the bell too much.
  2. Bell is very light and balls are also very light: The bell is less affected by the ball. Gradually the bell slows down.
  3. Bell is very heavy and the balls are very light: The bell is not affected at all. The balls are thrown without adding any effect on the bell.
  4. Bell is very heavy and the balls are also very heavy: Same as option 2 – The bell is less affected by the ball. Gradually the bell slows down.
Read More
All articles loaded
No more articles to load
[PictoBloxExtension]