In this guide, we’ll walk through the entire process of creating a smart desktop puppy, from choosing the right components to coding its intelligence and behavior.
Components Needed to Build an Electronic Desktop Puppy
Setting Up the LKD3588 SBC – Installing the Operating System and Software
How to Use Python for Coding Movements and Interactions
Designing and Assembling the Puppy’s Body
Programming the Puppy’s Behavior and AI Features
Now that your hardware and software are set up, it’s time to program the behavior and intelligence of your electronic pet puppy! We’ll use Python, OpenCV, and TensorFlow Lite to implement voice commands, facial recognition, and AI-driven behaviors.
1. Setting Up the Development Environment
Before we start coding, install the necessary Python libraries on your LKD3588 SBC (or another SBC) running Ubuntu. Open a terminal and enter the following:
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip -y
pip3 install numpy opencv-python tensorflow-lite sounddevice pyttsx3 SpeechRecognition
This installs:
✅ NumPy – Handles numerical data efficiently.
✅ OpenCV – Processes camera input for face tracking and detection.
✅ TensorFlow Lite – Runs lightweight AI models for facial recognition and movement prediction.
✅ Sounddevice & SpeechRecognition – Enable voice commands.
✅ pyttsx3 – Converts text to speech for audio responses.
2. Implementing Voice Commands for Interaction
First, let’s enable speech recognition so the puppy can respond to voice commands.
Step 1: Capture Voice Input
Create a Python script (voice_control.py) to listen for basic commands like “sit,” “wag tail,” or “come here.”
import speech_recognition as sr
def listen_for_command():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Say a command:")
recognizer.adjust_for_ambient_noise(source) # Reduce background noise
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio).lower()
print("You said:", command)
return command
except sr.UnknownValueError:
print("Sorry, I didn't catch that.")
return None
# Test function
if __name__ == "__main__":
while True:
cmd = listen_for_command()
if cmd in ["sit", "wag tail", "come here"]:
print(f"Executing: {cmd}")
✅ How It Works:
•Listens for a spoken command.
•Uses Google Speech API to convert speech to text.
•Matches the text with pre-defined commands.
Step 2: Make the Puppy Respond to Voice Commands
Now, modify the code to trigger actions based on commands:
def execute_command(command):
if command == "sit":
print("Puppy is sitting!")
# Add servo motor code to make the puppy sit
elif command == "wag tail":
print("Puppy is wagging its tail!")
# Add code to rotate the tail servo
elif command == "come here":
print("Puppy is moving towards you!")
# Add movement control code
if __name__ == "__main__":
while True:
cmd = listen_for_command()
if cmd:
execute_command(cmd)
✅ Now, when you say “sit”, the puppy will sit!
3. Enabling Facial Recognition for Owner Detection
Want your puppy to recognize you and respond accordingly? Use OpenCV and TensorFlow Lite for real-time face recognition.
Step 1: Capture Face Data
Before recognizing faces, collect training images of your face:
import cv2
camera = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
while True:
ret, frame = camera.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow("Face Detection", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
cv2.destroyAllWindows()
✅ This script detects and highlights faces using OpenCV.
Step 2: Train and Recognize the Owner’s Face
To recognize your face, use TensorFlow Lite’s pre-trained model:
import tensorflow as tf
import numpy as np
interpreter = tf.lite.Interpreter(model_path="face_model.tflite")
interpreter.allocate_tensors()
def recognize_face(face_image):
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Preprocess image
face_image = cv2.resize(face_image, (128, 128))
face_image = np.expand_dims(face_image, axis=0).astype(np.float32)
interpreter.set_tensor(input_details[0]['index'], face_image)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
return np.argmax(output_data)
# Use this function inside the camera loop to match the face
✅ This lets your puppy identify the owner and respond accordingly!
4. Making the Puppy Move Based on AI Decisions
Your puppy should move when called or react to objects.
Step 1: Control Servo Motors for Basic Movement
Use GPIO control to move servos:
import RPi.GPIO as GPIO
import time
servo_pin = 18 # Change based on your SBC
GPIO.setmode(GPIO.BCM)
GPIO.setup(servo_pin, GPIO.OUT)
servo = GPIO.PWM(servo_pin, 50) # 50 Hz PWM frequency
servo.start(7.5) # Neutral position
def move_tail():
servo.ChangeDutyCycle(5) # Tail wag left
time.sleep(0.5)
servo.ChangeDutyCycle(10) # Tail wag right
time.sleep(0.5)
if __name__ == "__main__":
for _ in range(5):
move_tail()
servo.stop()
GPIO.cleanup()
✅ Now the puppy’s tail wags when it recognizes you!
Step 2: Move Forward When Called
To make the puppy walk toward you, use motor control with PWM signals:
motor_left = 23
motor_right = 24
GPIO.setup(motor_left, GPIO.OUT)
GPIO.setup(motor_right, GPIO.OUT)
def move_forward():
GPIO.output(motor_left, GPIO.HIGH)
GPIO.output(motor_right, GPIO.HIGH)
time.sleep(2)
GPIO.output(motor_left, GPIO.LOW)
GPIO.output(motor_right, GPIO.LOW)
if __name__ == "__main__":
move_forward()
✅ When you say “come here”, the puppy moves toward you!
5. Combining Voice, Vision, and Motion
Finally, integrate everything so the puppy can:
✅ Recognize the owner’s face and wag its tail.
✅ Respond to voice commands like “sit” or “come here.”
✅ Move based on AI-based interactions.
Here’s how to combine these functions into one main program:
while True:
cmd = listen_for_command()
if cmd == "come here":
move_forward()
face_detected = recognize_face(camera_capture())
if face_detected:
move_tail()
print("Puppy recognizes you!")
Testing and Debugging Your Electronic Desktop Pet Puppy
Before showcasing your puppy, ensure it works correctly!
Common Issues and How to Fix Them
•Puppy doesn’t move? Check motor connections and power supply.
•Not responding to voice? Improve microphone sensitivity.
How to Optimize SBC Power Consumption
•Use sleep modes when idle.
•Adjust CPU load balancing for efficiency.
Final:
With this AI-powered programming, your electronic pet puppy can:
✅ Recognize and respond to your face.
✅ Follow voice commands.
✅ Move and interact like a real pet.
Now, you have a fully interactive, smart desktop puppy!