/* * servo-control.cpp * * Created on: 12.01.2021 * Author: frank */ #include "servo-control.hpp" SimplexNoise sn; int angle_to_dxl_servo_position(const int deg); int rpm_to_dxl_servo_speed(const int rpm); Mood mood; #define WEIGHT_COUNT 6 //enter number of weights here for array size float matrix_weights[SERVO_COUNT][WEIGHT_COUNT]; //mapping outputs, sensors/moods #define W_PITCH 0 #define W_ROLL 1 #define W_NOISE 2 #define W_NOISESLOW 3 #define W_SIN 4 #define W_COS 5 String weightNames[] = {"Pitch","Roll","Noise","NoiseSlow","Sin","Cos"}; unsigned long last_overloaderror_millis; bool overloaderror_flag=false; dxl_servo servos[SERVO_COUNT]; void matrix_weights_update(){ //0=pitch //1=roll //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; float map_sum=map_mode_noise+map_mode_rollpitch+map_mode_slither+map_mode_sleeping; map_mode_noise/=map_sum; //divide mapping so the sum will be 1.0 map_mode_rollpitch/=map_sum; map_mode_slither/=map_sum; map_mode_sleeping/=map_sum; /* Serial.print(map_mode_noise); Serial.print(","); Serial.print(map_mode_rollpitch); Serial.print(","); Serial.print(map_mode_slither); Serial.print(","); Serial.print(map_mode_sleeping); Serial.println(); */ //Mode Noise matrix_weights[0][W_NOISE]=90.0 *map_mode_noise; matrix_weights[0][W_NOISESLOW]=0.0 *map_mode_noise; matrix_weights[1][W_NOISE]=70.0 *map_mode_noise; matrix_weights[1][W_NOISESLOW]=20.0 *map_mode_noise; matrix_weights[2][W_NOISE]=50.0 *map_mode_noise; matrix_weights[2][W_NOISESLOW]=40.0 *map_mode_noise; matrix_weights[3][W_NOISE]=20.0 *map_mode_noise; matrix_weights[3][W_NOISESLOW]=70.0 *map_mode_noise; matrix_weights[4][W_NOISE]=0.0 *map_mode_noise; matrix_weights[4][W_NOISESLOW]=60.0 *map_mode_noise; //Mode Roll Pitch matrix_weights[0][W_ROLL]=1.0* map_mode_rollpitch; matrix_weights[1][W_PITCH]=1.0* map_mode_rollpitch; matrix_weights[2][W_ROLL]=1.0* map_mode_rollpitch; matrix_weights[3][W_PITCH]=1.0* map_mode_rollpitch; matrix_weights[4][W_ROLL]=1.0* map_mode_rollpitch; //Mode Slither matrix_weights[0][W_COS]=30 *map_mode_slither; matrix_weights[1][W_SIN]=30 *map_mode_slither; matrix_weights[2][W_COS]=-30 *map_mode_slither; matrix_weights[3][W_SIN]=-30 *map_mode_slither; matrix_weights[4][W_COS]=30 *map_mode_slither; //Mode Sleeping matrix_weights[0][W_NOISESLOW]=20 *map_mode_sleeping; matrix_weights[1][W_NOISESLOW]=20 *map_mode_sleeping; matrix_weights[2][W_NOISESLOW]=30 *map_mode_sleeping; matrix_weights[3][W_NOISESLOW]=15 *map_mode_sleeping; matrix_weights[4][W_NOISESLOW]=10 *map_mode_sleeping; /* float sleeping=constrain(mapfloat(mood.wakefulness,0.005,0.1, 0,1),0,1); for(int i = 0; i < SERVO_COUNT ; i++){ matrix_weights[i][W_PITCH]*=sleeping; matrix_weights[i][W_ROLL]*=sleeping; matrix_weights[i][W_NOISE]*=sleeping; matrix_weights[i][W_NOISESLOW]*=constrain(sleeping,0.1,1); } */ } bool trasmitMatrixWeightsHeaderFlag=false; void transmit_matrix_weights() { if (!trasmitMatrixWeightsHeaderFlag) { //transmit header only one time trasmitMatrixWeightsHeaderFlag=true; Serial.print("mwheader"); //matrixweight header for (int i=0;i= 0; i--) { Serial.print(","); Serial.print(servos[i].current_torque); } Serial.println("]"); }