Table of Contents

Function Definition: stoprobot()

Parameters

Description

The function stops both the motors of the Quarky robot.

Example

The example demonstrates how to make a vertical robot pet that senses the hand on the IR sensor and acts accordingly in the Python Coding Environment.

Code

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

quarky.setorientation(2)
quarky.setirthreshold("IRL", 3000)
quarky.setirthreshold("IRR", 3000)

while True:
  if quarky.getirstate("IRL"):
    if quarky.getirstate("IRR"):
      quarky.cleardisplay()

    else:
      pass
      quarky.runrobot("LEFT", 100)
      time.sleep(0.3)
      quarky.stoprobot()

  else:
    pass
    if quarky.getirstate("IRR"):
      quarky.runrobot("RIGHT", 100)
      time.sleep(0.3)
      quarky.stoprobot()

    else:
      pass
      quarky.showemotion("happy")
      quarky.playsounduntildone("QuarkyIntro")

Output

Read More
The example demonstrates how to make a delivery robot that follows the line and stops when it reaches checkpoint 1 in the Python Coding Mode.

Code

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

cards.video("on", 0)
cards.enablebox()
cards.setthreshold(0.5)

quarky.setirthreshold("IRL", 3000)
quarky.setirthreshold("IRR", 3000)
quarky.initializelinefollower(35, 40, 10)

quarky.drawpattern("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

while True:
  if not (quarky.getirstate(35) and quarky.getirstate(34)):
    quarky.dolinefollowing()

  else:
    quarky.stoprobot()
    cards.analysecamera()

    if cards.isnumberdetected(1):
      quarky.drawpattern("ccccccccccccccccccccccccccccccccccc")
      break

    quarky.runrobot("FORWARD", 40)

Output

Read More
The example demonstrates how to make a line follower robot with Quarky in the Python Coding Environment.

Code

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

# User Defined Functions
def LED_Feedback():
  if quarky.getirstate("IRL"):
    quarky.setled(1, 1, [42, 255, 0], 100)

  else:
    pass
    quarky.setled(1, 1, [255, 0, 0], 100)

  if quarky.getirstate("IRR"):
    quarky.setled(7, 1, [42, 255, 0], 100)

  else:
    pass
    quarky.setled(7, 1, [255, 0, 0], 100)


quarky.setirthreshold("IRL", 3000)
quarky.setirthreshold("IRR", 3000)

while True:
  LED_Feedback()
  if (quarky.getirstate("IRL") and quarky.getirstate("IRR")):
    quarky.stoprobot()

  else:
    pass
    if quarky.getirstate("IRL"):
      quarky.runmotor("R", "FORWARD", 40)
      quarky.runmotor("L", "BACKWARD", 25)

    else:
      pass
      if quarky.getirstate("IRR"):
        quarky.runmotor("L", "FORWARD", 40)
        quarky.runmotor("R", "BACKWARD", 25)

      else:
        pass
        quarky.runrobot("FORWARD", 40)

Output

Read More
The example demonstrates how to make a simplified line following a robot with Quarky in the Python Coding Environment.

Code

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

quarky.setirthreshold("IRL", 3000)
quarky.setirthreshold("IRR", 3000)
quarky.initializelinefollower(35, 40, 10)

while True:
  if not (quarky.getirstate(35) and quarky.getirstate(34)):
    quarky.dolinefollowing()

  else:
    quarky.stoprobot()

Output

Read More
The example demonstrates how to control the motion of the robot using keyboard keys in the Python Coding Environment.

Code

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

while True:
  
  if sprite.iskeypressed("up arrow"):
    quarky.runrobot("FORWARD", 50)
  elif sprite.iskeypressed("down arrow"):
    quarky.runrobot("BACKWARD", 50)
  elif sprite.iskeypressed("left arrow"):
    quarky.runrobot("LEFT", 50)
  elif sprite.iskeypressed("right arrow"):
    quarky.runrobot("RIGHT", 50)
  else:
    quarky.stoprobot()

Output

Read More
Make-a-Square (1)
The example demonstrates how to make a square with Quarky robot.

Code

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

# imported modules
import time

for i in range(0, 4):
  quarky.runrobot("FORWARD", 100)
  time.sleep(1)
  quarky.stoprobot()
  quarky.runrobot("LEFT", 100)
  time.sleep(1.2)
  quarky.stoprobot()

Output

Make a Square

Read More
Learn how to use the Hand Gesture Classifier of the Machine Learning Environment to make a machine-learning model that identifies hand gestures and makes the Mars Rover move accordingly.

This project demonstrates how to use Machine Learning Environment to make a machine–learning model that identifies hand gestures and makes the Mars Rover move accordingly.

We are going to use the Hand Classifier of the Machine Learning Environment. The model works by analyzing your hand position with the help of 21 data points.

Hand Gesture Classifier Workflow

Follow the steps below:

  1. Open PictoBlox and create a new file.
  2. Select the coding environment as appropriate Coding Environment.
  3. Select the “Open ML Environment” option under the “Files” tab to access the ML Environment.
  4. Click on “Create New Project“.
  5. A window will open. Type in a project name of your choice and select the “Hand Gesture Classifier” extension. Click the “Create Project” button to open the Hand Pose Classifier window.
  6. You shall see the Classifier workflow with two classes already made for you. Your environment is all set. Now it’s time to upload the data.

Class in Hand Gesture Classifier

There are 2 things that you have to provide in a class:

  1. Class Name: It’s the name to which the class will be referred as.
  2. Hand Pose Data: This data can either be taken from the webcam or by uploading from local storage.

Note: You can add more classes to the projects using the Add Class button.
Adding Data to Class

You can perform the following operations to manipulate the data into a class.

  1. Naming the Class: You can rename the class by clicking on the edit button.
  2. Adding Data to the Class: You can add the data using the Webcam or by Uploading the files from the local folder.
    1. Webcam:
Note: You must add at least 20 samples to each of your classes for your model to train. More samples will lead to better results.
Training the Model

After data is added, it’s fit to be used in model training. In order to do this, we have to train the model. By training the model, we extract meaningful information from the hand pose, and that in turn updates the weights. Once these weights are saved, we can use our model to make predictions on data previously unseen.

The accuracy of the model should increase over time. The x-axis of the graph shows the epochs, and the y-axis represents the accuracy at the corresponding epoch. Remember, the higher the reading in the accuracy graph, the better the model. The range of the accuracy is 0 to 1.

Testing the Model

To test the model, simply enter the input values in the “Testing” panel and click on the “Predict” button.

The model will return the probability of the input belonging to the classes.

Export in Python Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Python Coding Environment if you have opened the ML Environment in Python Coding.

Code

The following code appears in the Python Editor of the selected sprite.

####################imports####################
# Do not change

import numpy as np
import tensorflow as tf
import time
sprite=Sprite('Tobi')
import time
quarky = Quarky()
rover = MarsRover(4, 1, 7, 2, 6)
# Do not change
####################imports####################

#Following are the model and video capture configurations
# Do not change

model=tf.keras.models.load_model(
    "num_model.h5",
    custom_objects=None,
    compile=True,
    options=None)
pose = Posenet()                                                    # Initializing Posenet
pose.enablebox()                                                    # Enabling video capture box
pose.video("on",0)                                                  # Taking video input
class_list=['forward','backward','left','right','stop']                  # List of all the classes
def runQuarky(predicted_class):
    if pose.ishanddetected():
      if predicted_class == "forward":
        rover.home()
        rover.setinangle(0)
        quarky.runtimedrobot("F",100,3)
      if predicted_class == "backward":
        rover.home()
        rover.setinangle(0)
        quarky.runtimedrobot("B",100,3)
      if predicted_class == "left":
        rover.home()
        rover.setinangle(40)
        quarky.runtimedrobot("L",100,3)
      if predicted_class == "right":
        rover.home()
        rover.setinangle(40)
        quarky.runtimedrobot("R",100,3)
      if predicted_class == "stop":
        quarky.stoprobot()
    else:
      quarky.stoprobot()

# Do not change
###############################################

#This is the while loop block, computations happen here
# Do not change

while True:
  pose.analysehand()                                             # Using Posenet to analyse hand pose
  coordinate_xy=[]
    
    # for loop to iterate through 21 points of recognition
  for i in range(21):
    if(pose.gethandposition(1,i,0)!="NULL"  or pose.gethandposition(2,i,0)!="NULL"):
      coordinate_xy.append(int(240+float(pose.gethandposition(1,i,0))))
      coordinate_xy.append(int(180-float(pose.gethandposition(2,i,0))))
    else:
      coordinate_xy.append(0)
      coordinate_xy.append(0)
            
  coordinate_xy_tensor = tf.expand_dims(coordinate_xy, 0)        # Expanding the dimension of the coordinate list
  predict=model.predict(coordinate_xy_tensor)                    # Making an initial prediction using the model
  predict_index=np.argmax(predict[0], axis=0)                    # Generating index out of the prediction
  predicted_class=class_list[predict_index]                      # Tallying the index with class list
  print(predicted_class)
  runQuarky(predicted_class)
    
  # Do not change

Logic

  1. If the identified class from the analyzed image is “forward,” the Mars Rover will move forward at a specific speed.
  2. If the identified class is “backward,” the Mars Rover will move backward.
  3. If the identified class is “left,” the Mars Rover will move left.
  4. If the identified class is “right,” the Mars Rover will move right.
  5. Otherwise, the Mars Rover will be in the home position , stopped.
def runQuarky(predicted_class):
    if pose.ishanddetected():
      if predicted_class == "forward":
        rover.home()
        rover.setinangle(0)
        quarky.runtimedrobot("F",100,3)
      if predicted_class == "backward":
        rover.home()
        rover.setinangle(0)
        quarky.runtimedrobot("B",100,3)
      if predicted_class == "left":
        rover.home()
        rover.setinangle(40)
        quarky.runtimedrobot("L",100,3)
      if predicted_class == "right":
        rover.home()
        rover.setinangle(40)
        quarky.runtimedrobot("R",100,3)
      if predicted_class == "stop":
        quarky.stoprobot()
    else:
      quarky.stoprobot()

Output

Read More
All articles loaded
No more articles to load