• Ready for review
  • 9. Code Editor

    This space allows for working on the Duckiedrone DD21 code for brown2022.

    The Code Editor page provides a Visual Studio (VS) coding environment for replacing modules of the Duckiedrone’s autonomous stack.

    Modules

    We call "modules" the software components that constitute the fully autonomous flight stack:

    • Altitude: combines IMU and ToF readings to compute the drone's altitude;

    • Optical Flow: Estimate the drone's movement from changes in the camera frame;

    • State Estimation: estimates the drone's position by combining data from various sensors;

    • PID Controller: Controls the robot's action in order to achieve the desired behavior (e.g., hover in place, move forward, etc.);

    • SLAM: todo Simultaneous localization and mapping module

    • Localization: todo

    Opening the terminals of all modules

     

    1. Press Ctrl + Shift + P (replace Ctrl with Command on macOS) to open the command palette.

    2. Start typing and select "Terminals: Run" by pressing Enter.

    After a few seconds, a terminal popup will appear from the bottom edge of VSCode, along with a list of terminal tabs, one for each component of the autonomous flight pipeline.

    If you happen to accidentally close one or more of your terminal tabs, simply re-run the command "Terminals: Run" from the command palette to recover the missing tabs.

    If you happen to accidentally mess up one of your terminals, simply close it and re-run the command "Terminals: Run" from the command palette to obtain a new, clean, terminal environment.

    Implementing a module

    There are two versions for each module: “student” and “default”.

    The code editor shows the “student” versions of modules only.

    The “default” versions are hidden from sight to avoid compromising basic drone functionalities by mistake. The “default” code is available to developers and instructors on the Duckietown Github.

    All modules provide the skeleton code to implement certain functionalities, but the actual core code is left for learners to implement.

    1. From the Explorer column, navigate to the directory src/ inside the brown2022 workspace.

      1. Each module <M> is implemented inside src/ as a ROS package.

      2. Each ROS package in this workspace comprises of a ROS node in src/<M>/src/<M>_node.py and a ROS launch file in src/<M>/launch/<M>_node.launch.

    For example, for the altitude module, the code is implemented inside the python file src/altitude/src/altitude_node.py and the integration with the ROS network is defined inside the launch file src/altitude/launch/altitude_node.launch.

    Running modules

    Each module has two versions:

    • default: pre-implemented and running on the drone out-of-the-box. This code is hidden from VSCode (and available on the Duckietown Github) to avoid compromising basic functionalities.

    • student: it is nice to have a prebuilt pipeline but to learn how things actually work, each module can be (re)implemented manually through VSCode.

    A dtm (DuckieTown Module) command is provided to easily execute each module.


    To run any module:

    1. Select the module: navigate to the terminal tab that belongs to the module you want to run by clicking on the module's name from the list in the terminal tabs

    2. Run the module: type the following commands in the terminal and press Enter depending on the desired version:

      1. default: dtm-run

      2. student: dtm-run --student

     

     

    Example

    By selecting the Altitude node and executing dtm-run, the default version of the altitude module will be executed. The following output will be printed on the terminal:

    duckie@chitu10:/code/user_ws/brown2022$ dtm-run Creating brown2022_altitude_1 ... done ==> Entrypoint INFO: The environment variable VEHICLE_NAME is not set. Using 'chitu10'. INFO: Network configured successfully. <== Entrypoint ==> Launching app... master has started, initiating launch ... logging to /tmp/log/4a27e0bc-b426-11ec-89e6-024284227139/roslaunch-chitu10-57.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://chitu10.local:42723/ SUMMARY PARAMETERS /chitu10/altitude_node/h_offset: 0.02 /rosdistro: noetic /rosversion: 1.15.14 NODES /chitu10/ altitude_node (altitude/altitude_node.py) ROS_MASTER_URI=http://chitu10.local:11311/ process[chitu10/altitude_node-1]: started with pid [82] [DEBUG] [1657882843.210113]: init_node, name[/chitu10/altitude_node], pid[82] [DEBUG] [1657882843.238652]: binding to 0.0.0.0 0 [DEBUG] [1657882843.268797]: bound to 0.0.0.0 41757 [DEBUG] [1657882843.290397]: ... service URL is rosrpc://chitu10.local:41757 [DEBUG] [1657882843.323570]: [/chitu10/altitude_node/get_loggers]: new Service instance [DEBUG] [1657882843.353294]: ... service URL is rosrpc://chitu10.local:41757 [DEBUG] [1657882843.366946]: [/chitu10/altitude_node/set_logger_level]: new Service instance [INFO] [1657882843.386231]: [/chitu10/altitude_node] Initializing... [INFO] [1657882843.500840]: [/chitu10/altitude_node] Found 0 user configuration files in '/data/config/nodes/altitude_node' [DEBUG] [1657882843.510812]: ... service URL is rosrpc://chitu10.local:41757 [DEBUG] [1657882843.520489]: [/chitu10/altitude_node/switch]: new Service instance [DEBUG] [1657882843.538030]: ... service URL is rosrpc://chitu10.local:41757 [DEBUG] [1657882843.546762]: [/chitu10/altitude_node/get_parameters_list]: new Service instance [DEBUG] [1657882843.564573]: ... service URL is rosrpc://chitu10.local:41757 [DEBUG] [1657882843.578988]: [/chitu10/altitude_node/request_parameters_update]: new Service instance [INFO] [1657882843.669087]: [/chitu10/altitude_node] Health status changed [STARTING] -> [STARTED] [DEBUG] [1657882843.758951]: node[/chitu10/altitude_node, http://chitu10.local:39591/] entering spin(), pid[82] [DEBUG] [1657882846.125978]: connecting to chitu10.local 34269 [DEBUG] [1657882846.201758]: connecting to chitu10.local 37403

     

    Going back to Robot > Mission Control, two things will be noticed:

    1. The “Altitude” Heartbeat monitor heart will have turned from red to green (if not set in override mode), indicating that the Altitude node is running:

       

    2. The “Altitude” visualization box will start streaming data:

    Troubleshooting

    Problem: I click on “Code Editor” and the environment does not load

    Solution: Go to Portainer > Containers > (show all) and you should see that the vscode is “stopped”. Check the box next to it and “Start” it.