void NumberField::set_value(int32_t new_value) { new_value = clip_value(new_value); if( new_value != value() ) { value_ = new_value; if( on_change ) { on_change(value_); } set_dirty(); } }
double run_trial() { int speed[2]={0,0}; //Maximum activation of all IR proximity sensors [0,1] //double maxIRActivation = 0; //get sensor data, i.e., NN inputs int j; for(j=0;j<NB_DIST_SENS;j++) { //printf("sensor %d reads %g\n",j,wb_distance_sensor_get_value(ps[j])); temp[j]=(((double)wb_distance_sensor_get_value(ps[j])-ps_offset[j])<0)?0:(((double)wb_distance_sensor_get_value(ps[j])-ps_offset[j])/((double)PS_RANGE)); } for(j=0;j<NB_PS;j++) { //printf("sensor %d reads %g\n",j,wb_distance_sensor_get_value(ps[j])); inputs[j]=(temp[2*j]+temp[(2*j)+1])/2.0; } inputs[4]= wb_distance_sensor_get_value(fs[0])-fs_offset[0]; //printf("floor sensor:%g\n",inputs[4]); // Run the neural network and computes the output speed of the robot run_neural_network(inputs, outputs); speed[LEFT] = clip_value(outputs[0],max_speed); //scale outputs between 0 and 1 speed[RIGHT] = clip_value(outputs[1],max_speed); //printf("L: %d; R: %d\n",speed[LEFT],speed[RIGHT]); // Set wheel speeds to output values wb_differential_wheels_set_speed(speed[LEFT], speed[RIGHT]); //left, right //printf("Set wheels to outputs.\n"); return compute_fitness(inputs[4]); return compute_fitness(inputs[4]); }