Unit 8: Programming the Robot
I. Orientation
Robot programming is the process of converting a task into ordered instructions that use sensors for perception, a controller for decision-making, and actuators for movement. In the Sierena Utility Robot U-BOT laboratory, the robot observes color, shape, or a path and then produces a programmed response through its motors and indicators.
- Input: Sensors provide measurable information such as reflected light, detected color, distance, or line position.
- Processing: The controller compares sensor readings with programmed conditions and selects an action.
- Output: Motors, LEDs, buzzers, or other actuators execute the selected response.
- Feedback: Sensor readings are repeatedly checked so that the robot can correct its motion or decision.
- Threshold: A numerical boundary separates conditions, such as “black line” from “white surface.”
- Calibration: Sensor values are measured under actual laboratory lighting and surface conditions before programming.
- Control loop: The repeated sequence is
sense -> decide -> act -> sense; it allows the robot to respond to changing conditions. - Coordinate convention: Motor speed and direction must be defined consistently; for example, positive speed may mean forward rotation.
- Safety condition: Testing begins with low motor speed and clear surroundings so that an incorrect program does not damage the robot or equipment.
II. Color Identification
A. Purpose and principle
Color identification enables the U-BOT to distinguish objects or surfaces by analyzing reflected light. A color sensor typically illuminates a target and measures the intensity of red, green, and blue components, represented as R, G, and B.
- Sensor reading: A target produces a reading such as
(R, G, B) = (210, 35, 25), which is strongly associated with red. - Relative comparison: Color is identified by comparing channel values rather than relying only on absolute brightness.
- Red condition:
R > GandR > B. - Green condition:
G > RandG > B. - Blue condition:
B > RandB > G.
- Red condition:
- Brightness effect: A dimly lit red object may produce lower values than a brightly lit red object, so calibration and ratios improve reliability.
- Sampling position: The sensor should face the object at a consistent distance and angle; changing the distance changes reflected intensity.
- Decision output: The program can stop, turn, display an indicator, or sort the object after identifying its color.
B. Robot programming for color identification
Robot programming for color identification uses sensor input, conditional statements, and actuator commands to classify a target and perform a corresponding action.
- Program sequence: The basic sequence is:
- Move the U-BOT toward the object.
- Stop at a fixed sensing distance.
- Read the color sensor.
- Compare the readings with calibrated conditions.
- Execute the action assigned to the detected color.
- Calibration values: Record readings for known red, green, blue, white, and black samples. For example, if red samples consistently satisfy
R > 1.5GandR > 1.5B, these ratios can form a practical red rule. - Conditional logic: Use mutually exclusive branches so that one object does not trigger multiple color actions.
- Pseudocode: The following uses
R,G, andBfor sensor-channel readings andmotor()for a motor-control command.
move_forward()
wait_until(distance_sensor <= 10 cm)
stop()
(R, G, B) = read_color()
if R > G and R > B:
display("RED")
turn_left(90 degrees)
else if G > R and G > B:
display("GREEN")
turn_right(90 degrees)
else if B > R and B > G:
display("BLUE")
stop()
else:
display("UNKNOWN")
reverse(5 cm)- Stable classification: Take several readings and use their average to reduce noise.
R_average = (R1 + R2 + R3) / 3Here, R1, R2, and R3 are three red-channel measurements, and R_average is the filtered value.
- Unknown condition: Include a tolerance band for colors that are too similar or too dark. An
UNKNOWNresult is safer than forcing an incorrect classification. - Actuator mapping: Write a clear table in the program design: red may mean left turn, green may mean right turn, and blue may mean stop. The physical action must match the laboratory instruction.
- Testing method: Test one known color at a time, then test colors in a mixed sequence. Check whether the U-BOT detects color before moving away from the object.
- Limitations: Ambient light, glossy surfaces, shadows, object height, and sensor saturation can change readings. Recalibration is required if the lighting or target material changes.
III. Shape Identification
A. Purpose and principle
Shape identification allows the U-BOT to distinguish objects according to geometric features such as boundary, width, height, corners, or the number of sides. A robot usually identifies shape indirectly through repeated sensor measurements rather than by human-like visual understanding.
- Detection method: A distance or optical sensor measures the object while the robot moves past it or scans across it.
- Profile formation: A sequence of readings forms a profile:
profile = [distance1, distance2, distance3, ..., distancen]Each distance is the measured separation between the sensor and the object at a particular time.
- Rectangle profile: A rectangular object can produce a relatively constant distance across a flat face, followed by sharp changes at its edges.
- Circle profile: A circular object generally produces a gradually changing distance as the sensor moves across its curved surface.
- Triangle profile: A triangular object may produce a shorter detected width and angled or changing boundaries.
- Feature extraction: Useful features include detected width, duration of detection, number of transitions, and rate of change in distance.
- Assumption: The object is presented in a known orientation and the sensor is mounted at a fixed height. Without these controls, the same shape can produce different profiles.
B. Robot programming for shape identification
Robot programming for shape identification converts sensor observations into geometric features and compares those features with programmed ranges.
- Detection window: Begin measuring when the sensor detects an object closer than a selected threshold, such as
distance < 15 cm, and stop when the object is no longer detected. - Width estimation: If the U-BOT moves at approximately constant speed, the object width can be estimated from detection time:
width = speed × detection_timeHere, width is the estimated object width in centimetres, speed is robot speed in centimetres per second, and detection_time is the duration of object detection in seconds.
- Boundary count: A sudden change from “no object” to “object” marks one boundary, while a later change back to “no object” marks another. This gives an approximate object span.
- Shape rules: A rule must use measurable limits rather than vague descriptions. For example, a broad constant-width profile may be classified as a rectangle, while a continuously changing profile may be classified as a circle.
- Pseudocode: In this example,
samplesstores sensor readings andfeaturescontains calculated measurements.
samples = []
start_timer()
while distance_sensor < 15 cm:
samples.append(read_distance())
move_forward_at(5 cm/s)
stop()
detection_time = timer_value()
features = calculate_profile_features(samples)
if features.flat_region > 70 percent:
shape = "RECTANGLE"
else if features.smooth_change == true:
shape = "CIRCLE"
else:
shape = "UNKNOWN"
display(shape)- Feature definition:
flat_regionis the percentage of readings that remain within a chosen distance tolerance;smooth_changeindicates that consecutive readings change gradually rather than abruptly. - Decision hierarchy: Check distinctive conditions first. If a circular object and an unknown object both show changing readings, add width or boundary tests to prevent ambiguous classification.
- Worked example: If the robot travels at
5 cm/sand detects an object for4 s, the estimated width is5 × 4 = 20 cm. This value can be compared with the expected size range for the laboratory object. - Repeatability: Keep motor speed constant, place objects on the same surface, and take readings at the same sensor height.
- Limitations: A single distance sensor may not identify complex or rotated shapes reliably. Shape recognition becomes more dependable when multiple sensors, a scanning motion, or a camera-based system is available.
IV. Path Tracking Using Sierena's Utility Robot U-BOT
A. Purpose and principle
Path tracking is the continuous control of robot motion so that the U-BOT remains over or near a marked route. In a common line-following arrangement, downward-facing sensors detect the contrast between a dark path and a light floor, and differential motor speeds steer the robot.
- Sensor positions: Two sensors may be mounted left and right of the robot’s centre line. Their readings indicate whether the path is left, right, or centred.
- Binary interpretation: A sensor output can be converted into
0or1, where the chosen meaning must be calibrated; for example,1 = dark line detected. - Error concept: Let
x_pathbe the path position andx_robotbe the robot centre position.
error = x_path - x_roboterror = 0 means the robot is centred; a positive or negative value indicates displacement to one side.
- Differential drive: Turning is produced by changing left and right motor speeds.
- Left turn: Reduce the left motor speed or increase the right motor speed.
- Right turn: Reduce the right motor speed or increase the left motor speed.
- Feedback requirement: The robot must read the path sensors repeatedly while moving, rather than making one decision at the beginning.
B. Robot programming for path tracking using Sierena's Utility Robot U-BOT
Robot programming for path tracking using Sierena's Utility Robot U-BOT combines sensor conditions with motor-speed control to keep the robot aligned with a marked path.
- Initial setup: Place the U-BOT so that the path lies between or beneath the tracking sensors. Confirm that both motors move forward when commanded with the forward direction.
- Calibration procedure: Measure sensor readings over the path and over the surrounding surface. Select a threshold between the typical dark and light values.
- Two-sensor logic: With
LandRrepresenting left and right sensor states, a basic controller is:
if L == 0 and R == 0:
move_forward()
else if L == 1 and R == 0:
turn_left()
else if L == 0 and R == 1:
turn_right()
else:
stop_or_search()In this example, 1 means “line detected” and 0 means “line not detected”; reverse these meanings if the sensor calibration requires it.
- Both sensors off line: If
L == 0andR == 0, the robot may be centred over a narrow line, or it may have lost the path. The correct response depends on sensor spacing and the line width. - Both sensors on line: If
L == 1andR == 1, the robot may be over a wide line, a junction, or an incorrectly positioned path. A stop or search routine prevents uncontrolled motion. - Proportional correction: With several sensors, calculate a weighted position error and adjust motor speeds smoothly:
correction = Kp * error
left_speed = base_speed - correction
right_speed = base_speed + correctionKp is the proportional gain, error is the measured path-position error, and base_speed is the normal forward speed.
- Gain effect: A small
Kpproduces weak correction and may allow the robot to leave the path. A largeKpcan cause rapid left-right oscillation. Increase the gain gradually while observing motion. - Speed limits: Restrict each command to the permitted motor range:
left_speed = limit(left_speed, 0, maximum_speed)
right_speed = limit(right_speed, 0, maximum_speed)maximum_speed is the safe highest programmed speed, and limit() prevents invalid or unsafe values.
- Junction handling: Program intersections separately from ordinary tracking. A junction may require the robot to stop, count branches, or select a predefined direction.
- Recovery routine: When the path is lost, stop briefly, rotate toward the last known error direction, and resume tracking when a sensor detects the line.
- Testing sequence: Test first on a straight path, then on gentle curves, sharp curves, and junctions. Record the speed, sensor threshold, and correction values for each test.
- Limitations: Tracking accuracy is affected by line width, surface reflectivity, sensor height, motor mismatch, battery voltage, and sharp turns. A controller that works on a clean white floor may fail on a reflective or uneven surface.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →