NewPing::NewPing(uint8_t trigger_pin, uint8_t echo_pin, unsigned int max_cm_distance) { #if DO_BITWISE == true _triggerBit = digitalPinToBitMask(trigger_pin); // Get the port register bitmask for the trigger pin. _echoBit = digitalPinToBitMask(echo_pin); // Get the port register bitmask for the echo pin. _triggerOutput = portOutputRegister(digitalPinToPort(trigger_pin)); // Get the output port register for the trigger pin. _echoInput = portInputRegister(digitalPinToPort(echo_pin)); // Get the input port register for the echo pin. _triggerMode = (uint8_t *) portModeRegister(digitalPinToPort(trigger_pin)); // Get the port mode register for the trigger pin. #else _triggerPin = trigger_pin; _echoPin = echo_pin; #endif set_max_distance(max_cm_distance); // Call function to set the max sensor distance. #if (defined (__arm__) && (defined (TEENSYDUINO) || defined(PARTICLE))) || DO_BITWISE != true pinMode(echo_pin, INPUT); // Set echo pin to input (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode). pinMode(trigger_pin, OUTPUT); // Set trigger pin to output (on Teensy 3.x (ARM), pins default to disabled, at least one pinMode() is needed for GPIO mode). #endif #if defined (ARDUINO_AVR_YUN) pinMode(echo_pin, INPUT); // Set echo pin to input for the Arduino Yun, not sure why it doesn't default this way. #endif #if ONE_PIN_ENABLED != true && DO_BITWISE == true *_triggerMode |= _triggerBit; // Set trigger pin to output. #endif }
void CharacterCamera::_set(const String& p_name, const Variant& p_value) { if (p_name=="type") set_camera_type((CameraType)((int)(p_value))); else if (p_name=="orbit") set_orbit(p_value); else if (p_name=="height") set_height(p_value); else if (p_name=="inclination") set_inclination(p_value); else if (p_name=="max_orbit_x") set_max_orbit_x(p_value); else if (p_name=="min_orbit_x") set_min_orbit_x(p_value); else if (p_name=="max_distance") set_max_distance(p_value); else if (p_name=="min_distance") set_min_distance(p_value); else if (p_name=="distance") set_distance(p_value); else if (p_name=="clip") set_clip(p_value); else if (p_name=="autoturn") set_autoturn(p_value); else if (p_name=="autoturn_tolerance") set_autoturn_tolerance(p_value); else if (p_name=="autoturn_speed") set_autoturn_speed(p_value); }
/** * @brief Calculates the direction and the speed of the movement * depending on the target. */ void TargetMovement::recompute_movement() { if (target_entity != NULL) { // the target may be a moving entity target_x = target_entity->get_x(); target_y = target_entity->get_y(); } if (get_x() != target_x || get_y() != target_y) { finished = false; double angle = Geometry::get_angle(get_x(), get_y(), target_x, target_y); int dx = target_x - get_x(); int dy = target_y - get_y(); sign_x = (dx >= 0) ? 1 : -1; sign_y = (dy >= 0) ? 1 : -1; if (std::fabs(angle - get_angle()) > 1E-6 || get_speed() < 1E-6) { set_speed(speed); set_angle(angle); set_max_distance((int) Geometry::get_distance( get_x(), get_y(), target_x, target_y)); } } }
unsigned int NewPing::ping(unsigned int max_cm_distance) { if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance. if (!ping_trigger()) return NO_ECHO; // Trigger a ping, if it returns false, return NO_ECHO to the calling function. #if URM37_ENABLED == true #if DO_BITWISE == true while (!(*_echoInput & _echoBit)) // Wait for the ping echo. #else while (!digitalRead(_echoPin)) // Wait for the ping echo. #endif if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance. #else #if DO_BITWISE == true while (*_echoInput & _echoBit) // Wait for the ping echo. #else while (digitalRead(_echoPin)) // Wait for the ping echo. #endif if (micros() > _max_time) return NO_ECHO; // Stop the loop and return NO_ECHO (false) if we're beyond the set maximum distance. #endif return (micros() - (_max_time - _maxEchoTime) - PING_OVERHEAD); // Calculate ping time, include overhead. }
void NewPing::ping_timer(void (*userFunc)(void), unsigned int max_cm_distance) { if (max_cm_distance > 0) set_max_distance(max_cm_distance); // Call function to set a new max sensor distance. if (!ping_trigger()) return; // Trigger a ping, if it returns false, return without starting the echo timer. timer_us(ECHO_TIMER_FREQ, userFunc); // Set ping echo timer check every ECHO_TIMER_FREQ uS. }
/** * @brief Notifies this movement that the object it controls has changed. */ void RandomMovement::notify_object_controlled() { StraightMovement::notify_object_controlled(); set_max_distance(max_distance); }
/** * @brief Sets the entity to be controlled by this movement object. * @param entity the entity to control */ void RandomMovement::set_entity(MapEntity *entity) { Movement::set_entity(entity); set_max_distance(max_distance); }