#include "Arduino.h" #include "behaviour.h" SimplexNoise sn; Mood mood; float matrix_weights_main[SERVO_COUNT_MAIN][WEIGHT_COUNT]; //mapping outputs, sensors/moods float matrix_weights_peripheralL[SERVO_COUNT_PERIPHERAL][WEIGHT_COUNT]; float matrix_weights_peripheralR[SERVO_COUNT_PERIPHERAL][WEIGHT_COUNT]; void updateMatrixWeights(unsigned long millis,bool bellyup, bool body_present, bool contact_main, bool contact_peripheralL, bool contact_peripheralR, float pitch, float roll){ static unsigned long last_weights_update=0; if (millis-last_weights_update>WEIGHT_UPDATE_INTERVAL) { last_weights_update=millis; //float map_mode=constrain(mapfloat(mood.wakefulness,0,0.2, 1,0),0,1); //0=pitchroll control, 1=noise //float map_mode=constrain(mapfloat(mood.shakiness,0,0.2, 1,0),0,1); //0=pitchroll control, 1=noise /*float map_mode_noise=constrain(mapfloat(mood.wakefulness,0,0.2, 0,1),0,1); float map_mode_rollpitch=constrain(mapfloat(mood.shakiness,0,0.5, 0,1),0,1); float map_mode_slither=0; float map_mode_sleeping=mood.loneliness;*/ static float map_mode_rollpitch=0; static float map_mode_walking=0; static float map_mode_sleeping=0; static float map_mode_noise=0; if (body_present) { map_mode_rollpitch+=0.3 *WEIGHT_UPDATE_INTERVAL/1000.0; map_mode_walking-=0.5 *WEIGHT_UPDATE_INTERVAL/1000.0; map_mode_noise-=0.2 *WEIGHT_UPDATE_INTERVAL/1000.0; }else{ map_mode_rollpitch-=.2 *WEIGHT_UPDATE_INTERVAL/1000.0; if (bellyup) { map_mode_walking+=0.3 *WEIGHT_UPDATE_INTERVAL/1000.0; map_mode_noise-=.2 *WEIGHT_UPDATE_INTERVAL/1000.0; }else{ //sitting on a level survace map_mode_walking-=0.1 *WEIGHT_UPDATE_INTERVAL/1000.0; map_mode_noise+=0.3*WEIGHT_UPDATE_INTERVAL/1000.0; } } map_mode_walking=constrain(map_mode_walking,0.0,1.0); map_mode_rollpitch=constrain(map_mode_rollpitch,0.0,1.0); map_mode_noise=constrain(map_mode_noise,0.0,1.0); Serial.print("Walking: \t"); Serial.println(map_mode_walking); Serial.print("RollPitch: \t"); Serial.println(map_mode_rollpitch); Serial.print("Noise: \t"); Serial.println(map_mode_noise); Serial.println(); float map_sum=map_mode_walking+map_mode_rollpitch+map_mode_noise; map_mode_walking/=map_sum; map_mode_rollpitch/=map_sum; map_mode_noise/=map_sum; //divide mapping so the sum will be 1.0 analogWrite(PIN_VIBRATION,contact_main*map_mode_noise*64); Serial.print("Vibrt:"); Serial.println(contact_main*map_mode_noise*160); //reset all weights for (uint8_t i=0;iSERVOWEIGHT_UPDATE_INTERVAL) { last_servoweights_update=millis; static unsigned long millis_add; #define MILLISADD_MAX 100 millis_add+=constrain(mapfloat(mood.shakiness, 0.05,1 ,0,MILLISADD_MAX),0,MILLISADD_MAX); float vsin=sin((millis()+millis_add)/1000.0); float vcos=cos((millis()+millis_add)/1000.0); for (uint8_t i=0;i=0)?1:-1; //if angle positive, 1, else 0 if (i