#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 updateMood(unsigned long millis,float gyroX,float gyroY,float gyroZ,bool bellyup, bool body_present, bool contact_main, bool contact_peripheralL, bool contact_peripheralR,float height,float temp_ambient,float temp_object,float pumpspeed, float servoerror) { static unsigned long last_mood_update=0; if (millis-last_mood_update>MOOD_UPDATE_INTERVAL) { last_mood_update=millis; mood.arousal=0; mood.valence=0; } } 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; //### Update Mode ### static float map_mode_rollpitch=0; static float map_mode_walking=0; static float map_mode_sleeping=0; static float map_mode_noise=0; float aim_map_mode_rollpitch=0; float aim_map_mode_walking=0; float aim_map_mode_sleeping=0; float aim_map_mode_noise=0; if (body_present) { //attached aim_map_mode_rollpitch=1.0; }else{ //detached if (bellyup) { //belly up aim_map_mode_walking=1.0; }else{ //sitting on a level survace aim_map_mode_noise=1.0; } } map_mode_rollpitch=interpolateTo(map_mode_rollpitch,aim_map_mode_rollpitch,WEIGHT_UPDATE_INTERVAL/1000.0,0.3); map_mode_walking=interpolateTo(map_mode_walking,aim_map_mode_walking,WEIGHT_UPDATE_INTERVAL/1000.0,0.3); map_mode_sleeping=interpolateTo(map_mode_sleeping,aim_map_mode_sleeping,WEIGHT_UPDATE_INTERVAL/1000.0,0.3); map_mode_noise=interpolateTo(map_mode_noise,aim_map_mode_noise,WEIGHT_UPDATE_INTERVAL/1000.0,0.3); /* Serial.print("Walking: \t"); Serial.println(map_mode_walking); Serial.print("RollPitch: \t"); Serial.println(map_mode_rollpitch); Serial.print("Sleeping: \t"); Serial.println(map_mode_sleeping); Serial.print("Noise: \t"); Serial.println(map_mode_noise); Serial.println(); */ float map_sum=map_mode_walking+map_mode_rollpitch+map_mode_sleeping+map_mode_noise; map_mode_walking/=map_sum; map_mode_rollpitch/=map_sum; map_mode_sleeping/=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); //TODO, remove //reset all weights for (uint8_t i=0;iSERVOWEIGHT_UPDATE_INTERVAL) { last_servoweights_update=millis; static unsigned long millis_add; #define MILLISADD_MIN SERVOWEIGHT_UPDATE_INTERVAL*0.5 #define MILLISADD_MAX SERVOWEIGHT_UPDATE_INTERVAL*2 millis_add+=constrain(mapfloat(mood.arousal, -0.5,0.5 ,MILLISADD_MIN,MILLISADD_MAX),MILLISADD_MIN,MILLISADD_MAX); float vsin=sin((millis_add)/1000.0); float vcos=cos((millis_add)/1000.0); for (uint8_t i=0;i=0)?1:-1; //if angle positive, 1, else 0 if (iaimvalue) { result=aimvalue; } }else if (result>aimvalue){ result=result-timestep*speed; if (result