Goran Vuksic
Published

Teaching myCobot 280 to Slam Dunk Using Computer Vision

myCobot 280 robotic arm that uses computer vision to detect, pick up, and slam dunk a basketball.

IntermediateFull instructions provided47
Teaching myCobot 280 to Slam Dunk Using Computer Vision

Things used in this project

Hardware components

Elephant Robotics myCobot 280
×1

Software apps and online services

Edge Impulse Studio
Edge Impulse Studio

Story

Read more

Schematics

myCobot280

Code

Basketball detection

Python
Example code how to detect the basketball.
import cv2
import time
from edge_impulse_linux.image import ImageImpulseRunner
from pymycobot import MyCobot280

# Robot Setup
mc = MyCobot280('COM7', 115200)

# Load your model file
model_file = "basketball-model.eim"
runner = ImageImpulseRunner(model_file)

def main():
    with runner:
        runner.init()
        video_capture = cv2.VideoCapture(0) # 0 for built-in, 1 for external USB
        print("Model running... looking for a basketball.")

        while True:
            success, img = video_capture.read()
            if not success: break

            # Process frame for Edge Impulse
            features, _ = runner.get_features_from_image(img)
            res = runner.classify(features)

            if "classification" in res["result"]:
                scores = res["result"]["classification"]
                
                # Check for 'basketball' with > 85% confidence
                confidence = scores.get("basketball", 0)
                
                if confidence > 0.85:
                    print(f"🏀 Basketball found! ({confidence:.2f}) Moving arm...")
                    
                    # Parallel Command: Move arm and open gripper
                    mc.send_angles([-45, 10, -10, 0, 0, 0], 50)
                    mc.set_gripper_state(0, 80)
                    
                    # Safety delay to finish movement
                    time.sleep(4) 
                    
            if cv2.waitKey(1) & 0xFF == ord('q'): break

    video_capture.release()

if __name__ == "__main__":
    main()

Credits

Goran Vuksic
5 projects • 35 followers
Engineering manager, Microsoft AI MVP, cofounder of syntheticAIdata, father, hitchhiker through the galaxy...

Comments