Inheritance is a fundamental concept in object-oriented programming (OOP). It allows you to create a new class (child or subclass) that inherits attributes and methods from an existing class (parent or superclass). This helps in code reuse and makes it easier to maintain and extend programs.

Simple Example

Suppose we want to model animals:

class Animal:
    def speak(self):
        print("The animal makes a sound.")

class Dog(Animal):  # Dog inherits from Animal
    def speak(self):
        print("Woof!")

# Usage
a = Animal()
a.speak()      # Output: The animal makes a sound.

d = Dog()
d.speak()      # Output: Woof!

Explanation:


Extending Dobot Functionality

Let’s relate this to your robotic arm scenario.

Suppose you have a library called dobot with a class Dobot for controlling the robot arm.

You want to add extra features (like a “jump” movement and timed gripper/suction control) without changing the original Dobot class.

You do this by inheriting from dobot.Dobot and adding your own methods:

class MyDobot(dobot.Dobot):  # Inherit from dobot.Dobot
    def jump_to(self, x, y, z, r, height=50, wait=False):
        """
        Move the arm up by 'height', move horizontally, then down to target.
        Useful for moving over obstacles.
        """
        # Create this function by yourself

    def suck(self, enable, wait_time=0):
        """
        Enable/disable suction cup, optionally wait after action.
        """
        self._set_end_effector_suction_cup(enable)
        time.sleep(wait_time)

    def grip(self, enable, wait_time=0):
        """
        Enable/disable gripper, optionally wait after action.
        """
        self._set_end_effector_gripper(enable)
        time.sleep(wait_time)

How is this inheritance?

Real-World Analogy