ENED 1120 Robot Simulation

October 21, 2022

Project overview

The repository encompasses all the deliverables of the ENED 1120 - Engineering and Design Thinking - Spring 2020 Robot simulation project. The project’s objectives is: There are random boxes, each with their own barcode, spread across 16 shelves on the area; given a barcode input, the robot must scan the whole arena until it picks up the box with the right code.

Project deliverables include:

  • Specification review
  • Enginner Design Notebook detailing our meeting minutes, thought processes, and artifact images
  • Python code to demonstrate our robot’s working
  • Project management documents including our Gantt Chart


The project is part of the course ENED 1120. I worked together in a team of 4 over 10 weeks to construct a simple version of an automonous robot that can scan barcodes and pick boxes without human intervention. The hardware of the robot is made from LEGO blocks and the software would be code written in Python.

Initially, the code was embeded into the LEGO Mindstorm EV3, directly controlling the robot’s motors and sensors so that the robot would then be demonstrated in the university hall. However, after the mid-term demonstration, Covid-19 hit and lock-down instituted. Therfore, for the final demonstration, we had changed to write a simulation program instead, using shapes and graphs to simulate how the robot should move and work.

How I built it

For the mid-term demonstration, we used the library ev3dev2 to interface Python with the robot’s sensors and motors. The task at hand was to make the robot able to move straight and turn 180 degrees. We wrote multiple functions to make my code more concise and composeable so that I didn’t need to repeat complex logic.

  • For the subtask of turning 180 degree, we use a Gyro to read the robot’s rotated angle and stopping it when the robot achieved 180 deg. We also ensured the robot slowed down gradually as it get closer to the 180 degree mark so get the most accurate measurement and movement

  • For the subtask of going straight, we decided to also use the Gyro Sensor (since the sensor is already installed on the robot anyway for the Rotation subtask) and followed the PID algorithm to make the robot self-correct itself whenever it steers off.

For the final demonstration, we used the library matplotlib to draw shapes that represent my robot and the area, and continuously update the graph with new positions of the rectangles to show how our robot would move. The goal is to develop logic of the robot not only moving, but also picking up randomized boxes locations while avoiding road obstacles

Graphs with rectangles and circles

  • For this task, we opted to use Object Orientated Programming to manage the complexity of all the different components. The code includes Robot class for updating the robot’s coordinating and simulating the color sensor and the storage functionality, Backend class for generating all the numerical coordiates of boxes and obstacles, and Frontend class that uses matplotlib’s patches to actually draw out the components with colors

  • The logic for the robot’s movement was as followed: The robot will continuously scan through all the shelves until it encounters a box; then the robot slows down and takes small steps to read the box’s black-kwhite barcode using the color sensor’s reflective mode. If that is the correct box, the robot puts the box in its storage and navigate to a terminal location. If not, the loop continues.

Demonstration GIF


The first challenge was getting the robot to go straight. Possibly due to imperfect equipments, simple approaches such as putting both left and right motors to same powers, or using a simple read of the gyro sensor to steer the wheel back when the angle is too large did not work. Therefore, we had to research and eventually choose a the more advanced PID algorithm Correction = Error * Kp + Integral * Ki + Deriative * Kd. The difficult part of the PID algorithm is find the suitable Kp, Ki, and Kd values that suits our robot’s weight distribution and thus making the robot go straight. After hours of testing different set of values, we found the set of values that make the robot goes straight the most is (Kp = -0.149495; Ki = -0.0001; Kd = 0)

Another technical challenge was our barcode-scaning algorithm. In our initial algorithm, since our robot moves 4 units of distance a time, when it encounters a box, its goes backwards a little bit until it reaches the start of the current box, and then start scanning the barcode forward from there. However, if multiple boxes are adjacent, the robot might move backwards to much, leading to wrong reading and even infinite loops. Therefore, we had to change our barcode scanning algorithm to account for this case by keep track of the number of back steps the robot made to see if it has encountered the “adjacent boxes” scenario, so that the robot can move the correct amount of distance even if adjacent boxes cover its light sensor. More details can be found on our Engineering Notebook - page 31.

Accomplishments that I’m proud of

I am really proud of all Object-Orientated Programming code I was able to apply to the project. OOP is a piece of knowledge that I had endeavored to learn in my free time outside of the school curriculum, and knowing and using OOP really helped me manage the complexity of all the different parts of my program, allowing me to compose complex codes easily and develop great animation that really made my team stand out from the rest ✨. Seeing the effort of my learning paying huge dividends just truly made me proud and happy.

I am also proud of how our team worked so well and smooth thanks to all the project management tools and techniques that we learned and took took seriously. We had regular meetings with clear agendas beforehand and concrete set of tasks afterwards. Our discussions were constructive and we were able to leverage the strengths of each team member to progress all the different sub-goals really quickly. At the end of the course, we were ahead of the suggested schedule by two weeks, and have had many important milestones done before Covid hits, which really eased our work (and mind) going to the pandemic. Really proid and happy that I was able to work with my amazing teammates.

What I learned

  • Coding in Object-Orientated Python
  • Developing teamwork and leadership, using different decision-making and project management tools to help keep the progress going
  • Building strong and reliable structures with LEGO
  • Writing good and detailed content for our Engineering Notebook