<commit_before>/*setup() is the initilization stuff typically encountered in c and loop() is a while(true) infinite loop, 
 *these two functions can be replaced by standard C code
 *include necessary fils at the top of this file such as the <Wire.h>, be careful of including large libraries since memory is limited
 *Gesture detection framework:
 *sensor inputs: flex sensor input via ADC reading of voltage + acceleromoter input via I2C from accelerometer chip
 *program output: send state information via Xbee radio ONLY WHEN there is a state change (for now, we can use LED to verify the correctness of the program)
 *
 *There is on-chip capabiity to compute accelerometer data but it's hidden from developer so for now we rely on Arduino processor for all computing
 *Inputs: flex sensor reading and accel reading 
 *Outputs: state transition
 *States: idle, forward, backward, left turn in place , right turn in place (add differential drive on two wheels to realize forward left and forward right if necessary)
 *Stop and Balance: Fingers all relax
 *Forward: index and middle finger out  
 *Bakcup: fist
 *Left Turn: rotate hand left (turn speed determined by angle of rotation)
 *Right Turn: rotate hand right (turn speed determined by angle of rotation)
 *Catapult Throw: shake hand to trigger accelerometer 
 *
 *In each execution loop, we first acquire the accel readings (need to determine freq (John's job)) and ADC reading of flex sensor
 *use switch cases to see which state we should be in, if there is a state change, we go into that state
 *Albert's task: set up different states and action in those states(now just use distinguishable LED pattern so we can debug. Use serial.print for prelimanary testing but not in final testing)
 *
 */
 
/*notes on unit conversion*/

/*in order to save on expensive floating point conversion, we will use ADC read value instead,
 * this is more challenging in thinking about these quantities intuitively so here is a guideline
 * as to what accel reading means and what voltage ADC readout means.
 * Accel reading: signed 16-bit value for a full range of +- 4g. Example: at rest, reading is x=0, y=0, z=8000
 * flex sensor reading: ADC maps 0-5v to 0 - 1023, 
 * at rest, index reading is 562, middle reading 587, ring reading 600
 * at fist, index reading 766, middle reading 759, ring reading 796
 * choose middle value 650 to compare and determine if finers are relaxed or curled up
 * 
 * data acquisition rate: 781Hz loop speed without any computation, most time spent in writing 
 * to accelerometer. 
 */


#include<Wire.h>
#define relax(a) (((a)<(650))? (true):(false)) //whehter a finger is in relax state
enum state {forward_drive, backup, left_turn, right_turn, catapult_throw};
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
bool indexRelax, middleRelax, ringRelax;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU);
  Wire.write(0x1C);  // Accel_config register
  Wire.write(0x08);  // set to 08 (full_range +-4g)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU);
  Wire.write(0x24);  // Accel_config register
  Wire.write(0x09);  // set to 08 (full_range +-4g)
  Wire.endTransmission(true); <commit_msg>added msg for Albert<commit_after>/*setup() is the initilization stuff typically encountered in c and loop() is a while(true) infinite loop, 
 *these two functions can be replaced by standard C code
 *include necessary fils at the top of this file such as the <Wire.h>, be careful of including large libraries since memory is limited
 *Gesture detection framework:
 *sensor inputs: flex sensor input via ADC reading of voltage + acceleromoter input via I2C from accelerometer chip
 *program output: send state information via Xbee radio ONLY WHEN there is a state change (for now, we can use LED to verify the correctness of the program)
 *
 *There is on-chip capabiity to compute accelerometer data but it's hidden from developer so for now we rely on Arduino processor for all computing
 *Inputs: flex sensor reading and accel reading 
 *Outputs: state transition
 *States: idle, forward, backward, left turn in place , right turn in place (add differential drive on two wheels to realize forward left and forward right if necessary)
 *Stop and Balance: Fingers all relax
 *Forward: index and middle finger out  
 *Bakcup: fist
 *Left Turn: rotate hand left (turn speed determined by angle of rotation)
 *Right Turn: rotate hand right (turn speed determined by angle of rotation)
 *Catapult Throw: shake hand to trigger accelerometer 
 *
 *In each execution loop, we first acquire the accel readings (need to determine freq (John's job)) and ADC reading of flex sensor
 *use switch cases to see which state we should be in, if there is a state change, we go into that state
 *
 *Albert's task: set up different states and action in those states(now just use distinguishable LED pattern so we can debug. Use serial.print for prelimanary testing but not in final testing)
 *For example: use LED intensity to show degress of rotation of hand, use distinct blinking patterns to indicate forward_drive and idle state
 */
 
/*notes on unit conversion*/

/*in order to save on expensive floating point conversion, we will use ADC read value instead,
 * this is more challenging in thinking about these quantities intuitively so here is a guideline
 * as to what accel reading means and what voltage ADC readout means.
 * Accel reading: signed 16-bit value for a full range of +- 4g. Example: at rest, reading is x=0, y=0, z=8000
 * flex sensor reading: ADC maps 0-5v to 0 - 1023, 
 * at rest, index reading is 562, middle reading 587, ring reading 600
 * at fist, index reading 766, middle reading 759, ring reading 796
 * choose middle value 650 to compare and determine if finers are relaxed or curled up
 * 
 * data acquisition rate: 781Hz loop speed without any computation, most time spent in writing 
 * to accelerometer. 
 */


#include<Wire.h>
#define relax(a) (((a)<(650))? (true):(false)) //whehter a finger is in relax state
enum state {forward_drive, backup, left_turn, right_turn, catapult_throw}; //catapult_throw should be an interrupt, not a state
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
bool indexRelax, middleRelax, ringRelax;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU);
  Wire.write(0x1C);  // Accel_config register
  Wire.write(0x08);  // set to 08 (full_range +-4g)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU);
  Wire.write(0x24);  // Accel_config register
  Wire.write(0x09);  // set to 08 (full_range +-4g)
  Wire.endTransmission(true); 
{'fraction_non_alphanumeric': 0.07255069980005713, 'fraction_numerical': 0.022564981433876037, 'mean_word_length': 4.341723874904653, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '508915', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1928, 'n_words': 987}