The Braitenberg Robot is an autonomous mobile robot inspired by Braitenberg Vehicles. It reacts to environmental stimuli, such as light or obstacles, using simple sensor-based behaviors. The robot’s movements are determined by sensor input, enabling it to navigate and interact with its surroundings without predefined paths or waypoints.
About Tools and Materials:
Step 1: Hardware & Software Overview
Project Key Components
The 100 RPM BDC Motor with Encoder is used to rotate the radar mechanism in a full circle. The user can precisely control the motor and get the position through the built-in encoder.
Key Features
• Light-Based Behavior
Moves based on light intensity using sensors.
• Autonomous Navigation
Adjusts speed and direction dynamically.
• Multiple Modes
Fear (avoids light), Love (follows light), Aggression, and Wander.
• SMD Red Motor Control
Uses PWM for precise movement.
• Button-Controlled Mode Switching
Changes behavior with a button press.
• RGB LED Feedback
LED color indicates the active mode.
Step 2: Assemble
Ensure the SMD is powered and all connections are properly secured.
Project Wiring Diagram
Step 3: Run & Test
Run the Python script to initialize the system and scan for connected modules.
Observe the motor movement and RGB LED color changes based on light sensor inputs.
If the robot does not respond correctly, check the sensor values and motor operation.
Codes
from smd.red import *
import time
import sys
class Braitenberg:
""" Port and SMD ids are assigned. Modules connected to SMDs are printed.
The operation mode is set for velocity modes. Torque is enabled
"""
def __init__(self):
# SMD setup
self.port = "/dev/ttyUSB0"
self.m = Master(self.port)
self.m.attach(Red(0))
self.m.attach(Red(1))
print(self.m.scan_modules(0)) # Print the scanned modules for the first SMD ID.
print(self.m.scan_modules(1)) # Print the scanned modules for the second SMD ID.
# Motor setup
# SMD 0 is left motor
# SMD 1 is right motor
self.m.set_operation_mode(0, 2)
self.m.set_operation_mode(1, 2)
self.m.enable_torque(0, True)
self.m.enable_torque(1, True)
def map(self, value, fromLow, fromHigh, toLow, toHigh):
"""_summary_
Args:
value (_type_): value of light data from the light sensor
fromLow (_type_): minimum value of light coming from the light sensor
fromHigh (_type_): maximum value of light coming from the light sensor
toLow (_type_): minimum value of velocity
toHigh (_type_): maximum value of velocity
Returns:
_type_: Velocity value is returned in direct proportion to the incoming light value.
"""
return int((value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow)
def stop(self):
"""The motors are stopped by setting the Velocity value to 0.
"""
self.m.set_velocity(0, 0)
self.m.set_velocity(1, 0)
def get_light_values(self):
""" Incoming light data is assigned to right and left light variables
Returns:
_type_: right and left light values are returned
"""
left_light = self.m.get_light(0, 1)
right_light = self.m.get_light(0, 2)
return left_light, right_light
def fear(self):
""" The right motor is related to the light sensor on the right, the left motor is related to the light data
from the left sensor in direct proportion. Motor speeds increase in direct proportion to the light data, and
accordingly the robot tends to move away from the light.
"""
left_light, right_light = self.get_light_values()
if left_light is not None and right_light is not None:
# Adjust PWM values based on light intensity.
left_stim = self.map(left_light, 0, 2300, 40, 100)
right_stim = self.map(right_light, 0, 2300, 40, 100)
print(f"left_light {left_light}, righ_light {right_light} ")
self.m.set_velocity(0, -left_stim)
self.m.set_velocity(1, right_stim)
else:
self.stop() # Stop if any sensor is None.
def love(self):
"""
The right motor is related to the light sensor on the right, the left motor is inversely
related to the light data from the left sensor. Motor speeds increase inversely proportional to
the light data, and accordingly the robot tends to approach the light. However, as the robot
approaches the light source, its speed decreases.
"""
left_light, right_light = self.get_light_values()
if left_light is not None and right_light is not None:
# Adjust PWM values based on light intensity.
left_stim = self.map(left_light, 0, 1500, 100 ,0)
right_stim = self.map(right_light, 0, 1500, 100, 0)
if right_stim and left_stim > -1:
self.m.set_velocity(0, -left_stim)
self.m.set_velocity(1, right_stim)
else:
self.stop()
print(f"left_stim {left_stim}, right_stim {right_stim} ")
else:
self.stop() # Stop if any sensor is None.
def wander_around(self):
"""The right motor is inversely related to the light sensor on the left,
the left motor is inversely related to the light data from the right sensor.
Motor speeds increase inversely proportional to the light data, and accordingly
the robot tends to move away from the light. However, as the robot moves away from
the light source, its speed increases.
"""
left_light, right_light = self.get_light_values()
if left_light is not None and right_light is not None:
# Adjust PWM values based on light intensity.
left_stim = self.map(right_light, 0, 1500, 100, 0)
right_stim = self.map(left_light, 0, 1500, 100, 0)
self.m.set_velocity(0, right_stim)
self.m.set_velocity(1, -left_stim)
print(f"left pwm: {left_stim}, right pwm: {right_stim}")
else:
self.stop() # Stop if any sensor is None.
def agression(self):
""" The right motor is related to the light sensor on the right, the left motor is related to the light data
from the left sensor in direct proportion. Motor speeds increase in direct proportion to the light data, and
accordingly the robot tends to move away from the light.
"""
left_light, right_light = self.get_light_values()
if left_light is not None and right_light is not None:
left_stim = self.map(left_light, 0, 1500, 0, 100)
right_stim = self.map(right_light, 0, 1500, 0, 100)
self.m.set_velocity(0, -right_stim)
self.m.set_velocity(1, left_stim)
print(f"Left: {left_stim}, Right: {right_stim}")
else:
self.stop()
def run(self):
c = 0
while True:
button =self.m.get_button(0, 1)
if button == 1:
c += 1
time.sleep(0.4)
if c == 0:
print(0)
self.fear()
self.m.set_rgb(0, 1, red = 0, green = 0, blue = 255)
elif c == 1:
print(1)
self.love()
self.m.set_rgb(0, 1, red = 255, green = 0, blue = 255)
elif c == 2:
print(2)
self.agression()
self.m.set_rgb(0, 1, red = 255, green =0 , blue = 0)
elif c == 3:
print(3)
self.wander_around()
self.m.set_rgb(0, 1, red = 0, green = 255, blue = 0)
elif c > 2:
c = 0
if __name__ == "__main__":
try:
vehicle = Braitenberg()
vehicle.run()
except KeyboardInterrupt:
vehicle.stop()
sys.exit(0)
2x ()
()
()
2x ()
2x ()
()
()
The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the and meanwhile, actuate the motor for the continuous reading of the script.
The emits light in different colors by mixing red, green, and blue channels. This allows users to create a variety of lighting effects, controlled via the .
The serves as a physical interface for user input. Users can press the button to cycle through different colors for the , and if the button is held down, the system will rapidly cycle through colors, allowing for faster color selection.
The detects the intensity of the surrounding light and allows the system to decide when to automatically turn on or off the , depending on the environment’s lighting conditions.
Connect the to the PC or Arduino board using a or .
Connect the with encoders to the motor ports of the SMD.
Attach the , , and to the SMD using RJ-45 cables.
Power on the and ensure all connections are secure.
Press the to switch between different robot behaviors (Fear, Love, Aggression, Wander).