Don't like ads? Help support the Mercs by becoming a Supporter or Auxiliary Member today! (You will need to be logged into the store)
Official Members also get to use the forum ad-free - so kit up and join us!


 Remote rangefinder control

  • 0 Replies
  • 2929 Views

Bfahome


    *
  • 167
  • I'm sure it will all work out in the end!
Remote rangefinder control
« on: Mar 26, 2016, 09:42 PM »
I've seen the various tutorials on how to turn a small RC car into a rangefinder servo that lets you wirelessly control the position, and I'm pretty sure there are kits that do the same kind of thing (not sure on this, haven't really looked into it, I want to go full DIY on this),  But neither of those would give me the level of control over the rangefinder behavior that I'm looking for.

I'd settled on a servo and microcontroller, but wasn't yet sure about how I'd control it.  I knew I wanted something wireless from the gauntlet, but after ordering an RF link and testing it I found that it didn't agree with the servo, so I'd need to do some deeper modifications in the code for it to work.  So I switched to my fallback idea, which was to use the infrared receiver from a broken iHome I'd disassembled with the IR transmitter in its remote control.

I mean it works on TV, so why not here?

(Ignore the bright spinning lights, those are just for giggles.  I plan on having that in the RF cap, acting as if something were being projected to my eyes.)


So I got a basic test circuit working.  The transmitting LED is wired to an Adafruit Pro Trinket, which also has a switch running to it.  The basic logic of the code is if the switch is in one position, send the signal for "up", and if it's in the other position (or in any other case) send the signal for "down".  This means it is always transmitting, but if I were to have two pushbutton inputs this could be avoided.

(All code based on demo sketches included with IRremote library.)

Code: [Select]
/*
   IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
   An IR LED must be connected to Arduino PWM pin 3.
   Version 0.1 July, 2009
   Copyright 2009 Ken Shirriff
   http://arcfn.com
*/


#include <IRremote.h>



IRsend irsend;

void setup()
{
  pinMode (A3, INPUT);
  pinMode (13, OUTPUT);
}

void loop() {
  if (digitalRead(A3) == HIGH) {
    irsend.sendSony(0xA10, 12);
    digitalWrite(13, HIGH);
    delay(50);
  }
  else {
    irsend.sendSony(0xA11, 12);
    digitalWrite(13, LOW);
    delay(50);
  }
}

For now, the receiver is being read by an Arduino Uno, though in the helmet I'll be using another Trinket due to space issues.  The receiver logic goes like:
- If the signal is for down and the rangefinder is up, move down
- If the signal is or down and the rangefinder is down, stay down
- If the signal is for up  and the rangefinder is down, move up
- if the signal is for up and the rangefinder is up, stay up

Code: [Select]
#include <Servo.h>
#include <IRremote.h>

int RECV_PIN = 11;
bool rfDown = false; // consider the rangefinder to be in the up position

IRrecv irrecv(RECV_PIN);
Servo myservo;
decode_results results;

void setup()
{
  myservo.attach(9);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX); //print value to serial monitor

    // if command says "down" and the rangefinder is up
    // moves rangefinder down slowly
    if (results.value == 0xA10 && rfDown == false) {
      for (int x = 0; x < 85; x++) {
        myservo.write(x);
        delay(7);
      }
      rfDown = true;
    }

    // if command says "down" and the rangefinder is down
    // keeps rangefinder down
    else if (results.value == 0xA10 && rfDown == true) {
      myservo.write(85);
    }

    // if command says "up" and the rangefinder is down
    // moves rangefinder up slowly
    else if (results.value == 0xA11 && rfDown == true) {
      for (int x = 85; x > 0; x--) {
        myservo.write(x);
        delay(7);
      }
      rfDown = false;
    }
   
    // if command says "up" and the rangefinder is up
    // keeps rangefinder up
    else if (results.value == 0xA11 && rfDown == false) {
      myservo.write(0);
    }

    irrecv.resume(); // Receive the next value
  }
}


So this is the setup I'll be moving forward with on my helmet, once I get to that stage in its construction.  The plan is to have the receiver in the far left corner of the T visor, so it can receive the signal, be enclosed in teh helmet, and not be too much in my vision.  The left gauntlet will be the one with the controller and transmitter, so that should keep it within range.

Logged
 


Don't like ads? Help support the Mercs by becoming a Supporter or Auxiliary Member today! (You will need to be logged into the store)
Official Members also get to use the forum ad-free - so kit up and join us!



Powered by EzPortal
SMF spam blocked by CleanTalk