<commit_before>
<img src="pics/header.jpg" width="100%">

[![Build Status](https://travis-ci.org/DFEC-R2D2/r2d2.svg?branch=master)](https://travis-ci.org/DFEC-R2D2/r2d2)

# R2-D2 Senior Design Project

This repo documents the progress of the R2-D2 design for the 2017-2018 class year. R2-D2's purpose, once
it is delivered, is to:

- Serve as an example of multi-diciplinary engineering
- Support internal events like: Major's Night, DF evnets, and DFEC events
- Support external events like: STEM outreach and recruiting events.

# Architecture

## Power

The power system is modeled around a common 12V system. Relays are used to route power for emergency stop, charging, or other reasons.

![](pics/design/R2-D2-Power-v2.png)

Although there are mulitple batteries, they are all the same type of battery and therefore take the
same type of charging. The battery chemestry and capacity is TBD.

## Data

The system data shows the wiring between the pi and all of the sensors and effectors. Most of the communications operates at 3.3v, however, there is a USB serial that operates at 5v (5V TTL). The pi uses all of the buses available to it: I2C at 100 Hz, SPI, and USB. The PWM to drive the servos is off loaded to a hardware servo controller board. Similarly, the PWM which drives the motors is offloaded to 2 different motor controllers (Sabertooth and SMC).

![](pics/design/r2d2-data.png)

## Software Operating Modes

![](pics/design/r2d2_states.png)

The system shall follow the transition diagram shown above with the following definitions:

- **Off:** No R2D2 software is running and the Raspberry Pi (RPi) may or may not be powered on. This is
  not so much a designed software state so much as a reality of "off".
- **Standby:** When R2 software is started, it will enter this state and remain until commanded to exit.
  No motor (servos, legs, or dome) are allowed to run. This state produces and is capable of recording
  telemetry. This state is the only state where charging will occur. When the power plug is connected,
  the robot will change from whatever state it is in to this one.
- **Remote Controlled:** When commanded into this state, the robot will except commands from the
  joystick. The commands will be followed except where sensor (TBD) detect hazards and prevent the
  operator from damaging the robot. In this state, all motors are enabled.
- **Display:** When commanded into this state, the robot acts like a robotic static display. The leg
  motors are not enabled, however the dome motor is able to move. This mode is entered either by
  a software command or external power supplied to the robot which will trigger relays and automatically
  cut power to the leg motors.
- **Autonomous [objective]:** When commanded into this mode, the robot will autonomous move and avoid obstacles
  using its onboard sensors (TBD). When any issue arrises (i.e., motor currents exceeded, loss of
  sensors prohibiting safe opperation, TBD) the robot will immediately go to standby mode.

The system shall be designed to run the R2 software as a Debian service under `systemd`
once everything works. During development, this won't be implemented for safety reasons.

# Statement of Work

[SOW](docs/design_2017-2018/R2D2-2017.pdf)

# Software

R2 is written primarily in python. The following libraries were developed for R2-D2:

- [Text-to-Astromech: ttastromech](https://pypi.python.org/pypi/ttastromech)
- [Simple Motor Controler: smc](https://pypi.python.org/pypi/smc)
- [Sabertooth Motor Controller: pysabertooth](https://pypi.python.org/pypi/pysabertooth)

The following are used:

- [mote](https://github.com/MomsFriendlyRobotCompany/mote)
- [fake_rpi](https://pypi.python.org/pypi/fake-rpi)
- [opencvutils](https://pypi.python.org/pypi/opencvutils)
- [nxp_imu](https://pypi.python.org/pypi/nxp-imu)
- [mcp3208](https://pypi.python.org/pypi/mcp3208)

The following was created for the purpose of R2D2's code simplicity, which combines the above codes into one python library file:

- [library]

The R2D2 code can be found in the directory called Final with the python file named run.py. Currently, the Raspberry Pi 3 image that we created allows R2D2 to automatically run this code when booted on. All the USB devices that are connected to the R2D2 are based on our actual model, and would need to be changed to match the serial information of the new device if you are considering making another R2D2.
<commit_msg>Readme Updated<commit_after>
<img src="pics/header.jpg" width="100%">

[![Build Status](https://travis-ci.org/DFEC-R2D2/r2d2.svg?branch=master)](https://travis-ci.org/DFEC-R2D2/r2d2)

# R2-D2 Senior Design Project

#####ALL UPDATED FILES CAN BE FOUND IN THE FOLDER LABELED "FINAL"

This repo documents the progress of the R2-D2 design for the 2017-2018 class year. R2-D2's purpose, once
it is delivered, is to:

- Serve as an example of multi-diciplinary engineering
- Support internal events like: Major's Night, DF evnets, and DFEC events
- Support external events like: STEM outreach and recruiting events.

# Architecture

## Power

The power system is modeled around a common 12V system. Relays are used to route power for emergency stop, charging, or other reasons.

![](pics/design/R2-D2-Power-v2.png)

Although there are mulitple batteries, they are all the same type of battery and therefore take the
same type of charging. The battery chemestry and capacity is TBD.

## Data

The system data shows the wiring between the pi and all of the sensors and effectors. Most of the communications operates at 3.3v, however, there is a USB serial that operates at 5v (5V TTL). The pi uses all of the buses available to it: I2C at 100 Hz, SPI, and USB. The PWM to drive the servos is off loaded to a hardware servo controller board. Similarly, the PWM which drives the motors is offloaded to 2 different motor controllers (Sabertooth and SMC).

![](pics/design/r2d2-data.png)

## Software Operating Modes

![](pics/design/r2d2_states.png)

The system shall follow the transition diagram shown above with the following definitions:

- **Off:** 
- **Standby:** 
- **Remote Controlled:**
- **Display:**

# Statement of Work

[SOW](docs/design_2017-2018/R2D2-2017.pdf)

# Software

R2 is written primarily in python. The following libraries were developed for R2-D2:

- [Text-to-Astromech: ttastromech](https://pypi.python.org/pypi/ttastromech)
- [Simple Motor Controler: smc](https://pypi.python.org/pypi/smc)
- [Sabertooth Motor Controller: pysabertooth](https://pypi.python.org/pypi/pysabertooth)

The following are used:

- [mote](https://github.com/MomsFriendlyRobotCompany/mote)
- [fake_rpi](https://pypi.python.org/pypi/fake-rpi)
- [opencvutils](https://pypi.python.org/pypi/opencvutils)
- [nxp_imu](https://pypi.python.org/pypi/nxp-imu)
- [mcp3208](https://pypi.python.org/pypi/mcp3208)

The following was created for the purpose of R2D2's code simplicity, which combines the above codes into one python library file:

- [library](https://github.com/DFEC-R2D2/r2d2/blob/master/Final/Code/library.py)

The sound files that R2D2 plays can be loaded in with the clips sound files and through the sounds.py with the extension of clips.json, which initializes the sound files to the sounds.py file.

- [sounds](https://github.com/DFEC-R2D2/r2d2/blob/master/Final/Code/sounds.py)

The R2D2 code can be found in the directory called Final with the python file named run.py. 

- [run](https://github.com/DFEC-R2D2/r2d2/blob/master/Final/Code/run.py)

Currently, the Raspberry Pi 3 image that we created allows R2D2 to automatically run this code when booted on. All the USB devices that are connected to the R2D2 are based on our actual model, and would need to be changed to match the serial information of the new device if you are considering making another R2D2. If needed, the image file can be acquired through the DFEC Department Instructor Major <NAME>.

The functions that are created for R2D2 can be followed below:

- **random_char(length):** This function creates a random character string with specified length as a input to use with TTastromech library. It receives as a input a length in integer, and outputs a string of that specified length.
- **standby(standbyflag):** This function is the standby mode function, it receives the standbyflag, which is set by the keypad on R2D2. This flag is set when 1 is pressed, and continues to be set until R2D2 is put into another mode. At this stage, R2D2 is sitting idle until another mode is pressed. This means that R2D2 will have no motor controls, and will not be reading from any of its sensor. No command can be given, unless its given predefined emotions from buttons 4, 5, and 6.
- **static(staticflag):** This function is the static mode function, it receives the staticflag, which is set by the keypad on R2D2. This flag is set when 2 is pressed, and continues to be set until R2D2 is put into another mode. The static display mode ensures that R2D2 does not have any motor controls, but reads from its sensors. All functions are available on static display mode except for the motors.
- **remote(remoteflag):** This function is the remote mode function, it reeives the remoteflag, which is set by the keypad on R2D2. This flag is set when 3 is pressed, and continues to be set until R2D2 is put into another mode. The remote mode ensure that R2D2 has full capabilities, such that the motor control works, and all its functionalities are present. R2D2 will be controlled through the PS4 controller. The instructions for connecting the PS4 controller to R2D2 can be found in the operations manual.
- **reboot(rebootflag):** This function is the reboot function. This can be called at any mode and will reboot R2D2. This function receives the rebootflag from the button *. Once this rebootflag is set, the function calls on a reboot command to the terminal, hence terminating all running processes and restarting the raspberry pi 3.
- **shutdown(shutdownflag):** This function is the shutdown function. This can be called at any mode and will reboot R2D2. This function receives the shutdownflag from the button #. Once this shutdownflag is set, the function calls on a shutdown command to the terminal, hence terminating all running processes and shutting down the raspberry pi 3.
- **happy():** This function does not have any inputs or outputs, as the commands are given from the function. The happy function turns on the green LED on the 8x8 matrix LED pads, and also spins the dome. The top hatch of R2D2 will open in a wave and close in a wave. This can be either called from the keypad button 4, or from the arrow hat on the controller.
- **confused():** This function does not have any inputs or outputs, as the commands are given from the function. The happy function turns on the orange LED on the 8x8 matrix LED pads. This can be either called from the keypad button 5, or from the arrow hat on the controller.
- **angry():** This function does not have any inputs or outputs, as the commands are given from the function. The happy function turns on the red LED on the 8x8 matrix LED pads, and plays the imperial theme sound. Once the theme sound is complete, it opens the top hatch of R2D2 and closes it afterwards. This can be either called from the keypad button 6, or from the arrow hat on the controller.
- **battery(battflag):** This function is automatically ran when R2D2 is powered on. It receives the battflag, which is set when R2D2 is powered on. This enables the user to gauge the battery level of the battery. This is only shown when the battery is plugged in. If it is powered through the wall cable, then it will display all red.
- **mode(standbyflag, staticflag, remoteflag):** This function is automatically ran when R2D2 is powered on. It receives the status of the standby, static, and remote flags and based on those flags, will turn on colors corresponding to the mode of R2D2. 





{'fraction_non_alphanumeric': 0.07054185539339038, 'fraction_numerical': 0.01987921489682939, 'mean_word_length': 4.332289803220036, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 23, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1001166', 'n_tokens_mistral': 3565, 'n_tokens_neox': 3317, 'n_words': 1717}