Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: face detection shield #121516
    avatarCPJ
    Participant

    Hi there,

    I can’t work out how to change my sketch just to detect a face (no winks or smiles needed).
    Also I have tried dozens of ways to put inn some code for an SR04 sensor. This is to stop the robot if it gets to close to an object.
    Any help would be really appreciated.

    Thanks

    in reply to: face detection shield #119131
    avatarCPJ
    Participant

    Thanks for your reply re using face detection in a robot to detect human presence and move towards them.
    I have it working to a fashion. I’ve used your example code as a starting point. The robot rotates slowly and scans for human faces.
    When detected it stops and moves forward to the person.
    However, my programming is very crude I’m a beginner). I have delays in there which I want to avoid. It has the wink counter in there which I want to remove. The rotation stops when a face is detected and moves forward but sometimes it doesn’t. I’ve added the code below
    /*

    Face Detector Shield Example

    This example shows an application on 1Sheeld’s face detector shield.

    By using this example, you can unlock a door by winking three times to
    the front camera.

    OPTIONAL:
    To reduce the library compiled size and limit its memory usage, you
    can specify which shields you want to include in your sketch by
    defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.

    */

    #define CUSTOM_SETTINGS
    #define INCLUDE_FACE_DETECTOR_SHIELD
    #define INCLUDE_TERMINAL_SHIELD
    #define INCLUDE_TEXT_TO_SPEECH_SHIELD
    #define INCLUDE_VOICE_RECOGNIZER_SHIELD

    /* Include 1Sheeld library. */
    #include <OneSheeld.h>

    /* A name for the LED on pin 13. */
    int ledPin = 13;

    /* A name for the relay on pin 12. */
    int relayPin = 12;

    /* A name for the winks counter. */
    int counter = 0;

    // MOTOR 1
    // Motor 1 PWM is connected to pin 3.

    const int pinPwm1 = 3;

    // Motor 1 DIR is connected to pin 2.

    const int pinDir1 = 2;

    // MOTOR 2
    // Motor 2 PWM is connected to pin 5.

    const int pinPwm2 = 5;

    // Motor 2 DIR is connected to pin 4.

    const int pinDir2 = 4;

    /*******************************************************************************
    * PRIVATE GLOBAL VARIABLES *
    *******************************************************************************/

    // Speed of the motor1.
    static int iSpeed1 = 0;

    // Acceleration of the motor1.
    static int iAcc1 = 1;

    // Speed of the motor2.
    static int iSpeed2 = 0;

    // Acceleration of the motor2.
    static int iAcc2 = 1;

    void setup()
    {
    /* Start communication. */
    OneSheeld.begin();
    /* Set the LED pin as output. */
    pinMode(ledPin,OUTPUT);
    /* Set the relay pin as output. */
    pinMode(relayPin,OUTPUT);

    pinMode(pinPwm1, OUTPUT);
    pinMode(pinDir1, OUTPUT);
    pinMode(pinPwm2, OUTPUT);
    pinMode(pinDir2, OUTPUT);

    }

    void loop()
    {
    /* Get the first face and check if it winks. */
    if(FaceDetector.getVisibleFace(0).getLeftEyeOpenProbability()==0)
    {
    /* Turn on the LED when winking. */
    digitalWrite(ledPin,HIGH);

    iSpeed1 = 1;
    iSpeed2 = 1;

    analogWrite(pinPwm1, iSpeed1);
    digitalWrite(pinDir1, LOW);

    analogWrite(pinPwm2, iSpeed2);
    digitalWrite(pinDir2, HIGH);

    TextToSpeech.say(“Life form detected”);

    /* Count the winks. */
    counter++;

    delay (50);

    iSpeed1 = 100;
    iSpeed2 = 100;

    analogWrite(pinPwm1, iSpeed1);
    digitalWrite(pinDir1, HIGH);

    analogWrite(pinPwm2, iSpeed2);
    digitalWrite(pinDir2, LOW);

    delay (2000);

    /* A slight delay. */
    OneSheeld.delay(1000);
    }else
    {
    /* Turn off the LED. */
    digitalWrite(ledPin,LOW);

    iSpeed1 = 50;
    iSpeed2 = 50;

    analogWrite(pinPwm1, iSpeed1);
    digitalWrite(pinDir1, HIGH);

    analogWrite(pinPwm2, iSpeed2);
    digitalWrite(pinDir2, HIGH);

    }

    /* Check the number of winks. */
    if(counter == 3)
    {
    /* Send success. */
    Terminal.println(“Success”);
    /* Open the lock. */
    digitalWrite(relayPin,HIGH);
    /* Reset counter. */
    counter=0;

    }

    }

    in reply to: face detection shield #117863
    avatarCPJ
    Participant

    Hi there,
    I’m using the face detector shield which is absolutely brilliant! I’m new to C++.
    I want to modify the example given by 1Sheeld to do something slightly different.
    I don’t need the wink count bit. I just need it to detect a face.
    I’m building an arduino based robot. The robot will turn slowly on it’s own axis.
    Whilst doing this I want the mobile mounted on the robot to detect a first face. At that point the robot will stop rotating and move forward towards the face. In other words my robot will detect human presence and move towards it. I will use an ultrasonic sensor to avoid objects. All I need is a bit of code based on the “if” function that will then engage the bit of the sketch which turns the motors on.
    The code I’m using for the motor control is as attached. It would be a really helpful starter for me if you could just add to this the face detector code I need – just so I can see how it works. I can develop the rest myself. Many thanks.

Viewing 3 posts - 1 through 3 (of 3 total)