Corner Kick is a web app that allows for the visualization of UBC Thunderbots' AI.
Table of content
You can start the visualizer by running:
roslaunch corner_kick corner_kick.launch
You can launch the application by running:
roslaunch rosbridge_server rosbridge_websocket.launch
and in another window:
yarn
yarn start
A window should open with the application in development mode.
You can test the code by running
yarn test
To be able to run tests everytime a file changes, run
yarn test:watch
You can test the various UI elements by running
yarn storybook
A window should appear showing the various UI elements of Corner Kick
The project is defined as follow:
config
- contains webpack (build tool) configuration fileslaunch
- contains roslaunch filescripts
- contains build related scriptssrc
assets
- contains image assetscomponents
- contains repeatable UI componentscontainers
- contains high-level UI components (logger, visualizer, etc.)constants
- contains fixed values used throughout the applicationstore
- contains logic for the application Redux statestyle
- contains application styling and themingtypes
- contains all Typescript typesutils
- contains misc code
storybook
- contains Storybook config.prettierrc
- configuration for autoformating toolCMakeLists.txt
- cmake build scriptcommon.d.ts
- definition file for file assetspackage.json
- specifies dependencies, dev and build scripts.package.xml
- specifies ros dependenciestsconfig.json
- configuration file for typescript compilertslint.json
- configuration for typescript linteryarn.lock
- autogenerated lock file for javascript dependencies
We are using a fixed version of Yarn in this project, to ensure that all developers
are using the same tooling for this project. As such, Yarn is included in this project
in the scripts
directory. Regardless of the version of Yarn installed on your system,
it will detect the committed version and use that instead.
Currently, we are using Yarn version 1.13.0.
The visualizer will consist of multiple pages, each of which serve a single purpose. Each page will be divided into sections as follow:
- Main: Contains the primary focus of the page
- Sidebar title: Contains the page title and additional options specific to the page
- Sidebar: Contains additional controls or information relevant to the current page
- Sidebar control: Contains navigation controls to switch between pages
- Console: Contains views visible across the application
- Footer: Contains simple breadcrumbs of information relevant to the application as a whole or to the current page
The application's primary layout is defined in index.html. The theme for the application is defined in Theme.tsx
We are using Redux to manage the application state. Simply put, in Redux, the state is an immutable object. It can only be replaced by a new version of itself when some sort of action occurs in the application. This action is captured by a reducer function, which accepts the current state and the action, and returns a new state, with potentially new values based on the action received.
React, then, becomes an extension of the global Redux state and does not contain state of its own. When the global state changes, the React UI will automagically change to adapt to the new state.
You can debug the Redux store by installing the Redux debugger on Chrome or Firefox. It allows to observe all actions and changes to the Redux state happening inside the application.
Reducer functions are the cornerstone of the Redux approach. Once a Redux action is dispatched, reducer functions determine what the new state will look like as a result of the action sent. Reducer functions do not permit for any side-effects to ensure a deterministic behaviour. For a state and action, the same new state should be returned by the reducer funtion. This, however, does not permit for more complex logic, such as communicating with ROS, to occur. To allow for this, we introduce sagas, which can intercept and act on Redux action. They can conduct some business logic work, and reflect the result of this work in the state by emmiting a Redux action when needed.
For more information about reducer functions, read the official Redux doc on that topic. For more information about Redux sagas, read the official Redux saga doc.