Giter VIP home page Giter VIP logo

robotsimulation's Introduction

Existing Bugs :

  1. The SimulatedRobotWithCommunicationDelay class's set_position method creates a new thread but doesn't start it. The thread_update.start() line is missing.
  2. The SimulatedRobotWithCommunicationDelay class's set_navigation_command method creates a new thread but doesn't start it. The thread_update.start() line is missing.
  3. The SimulatedRobotWithCommunicationDelay class's set_navigation_command method uses the self._robot variable without locking it first, which could cause synchronization issues in a multithreaded environment.
  4. The MissionController class's _poll_position method calls itself recursively without an exit condition, which could lead to a stack overflow error.
  5. The MissionController class's _poll_position method doesn't use a lock when accessing the current_waypoint_idx variable, which could cause synchronization issues in a multithreaded environment.

Changelog for fixing issues and refactoring code for readability and maintainability.

To address these issues, you can add the following modifications to the code:

BUG FIXES :

  1. In the SimulatedRobotWithCommunicationDelay class's set_position method, add Thread(target=self._update_position, args=(position,)).start()
  2. In the SimulatedRobotWithCommunicationDelay class's set_navigation_command method, add Thread(target=self._update_position, args=(waypoint,)).start()
  3. In the SimulatedRobotWithCommunicationDelay class's set_navigation_command method, add a lock before accessing the self._robot variable by defining lock = Lock() in the class constructor and using with lock: when accessing the self._robot variable.
  4. In the MissionController class's _poll_position method, add a condition is_mission_completed to the recursive call by checking if the mission has been completed. That is to check if the current waypoint index has reached the last waypoint in the trajectory.
  5. In the MissionController class's _poll_position method, add a lock before accessing the current_waypoint_idx variable by defining lock = Lock() in the class constructor and using with lock: when accessing the current_waypoint_idx variable.

REFACTORIZATION for readability and maintainability
mission_controller.py

  1. Calling seperate method _start_polling_position to start the polling thread for better maintainability.
  2. Initialize trajectory to None within constructor and set current_waypoint_idx to 0 whenever a new trajectory is set in set_trajectory method
  3. Added a is_mission_completed method to encapsulate the logic for checking if the mission is completed.
  4. Added a check in the _poll_position method to avoid infinite recursion in case the trajectory is not set.

SimulatedRobotWithCommunicationDelay

  1. Added _update_position_with_delay and called it as the target within set_navigation_command to start a new thread and secure it with a lock

INPUT VALIDATION: Added below input validation

mission_controller.py

  1. Check if robot is instance of SimulatedRobot or SimulatedRobotWithCommunicationDelay in the constructor
  2. Check if trajectory is a numpy array

SimulatedRobot

  1. Check if update_position_callback is callable and not None in the constructor
  2. Check if waypoint, initial_position and position are a numy array

SAMPLE OUTPUT

Creating SimulatedRobot!
Creating MissionController!
Sending waypoint 0
Commanding robot to move to [2. 0.]
Sending waypoint 1
Commanding robot to move to [3. 0.]
Commanding robot to move to [2. 0.]
Commanding robot to move to [3. 0.]
Robot is now at [2. 0.]
Robot is now at [3. 0.]
Test complete

robotsimulation's People

Contributors

pradeeptyagi23 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.