Shop OBEX P1 Docs P2 Docs Learn Events
ir remote control code help — Parallax Forums

ir remote control code help

zemkaczzemkacz Posts: 19
edited 2008-03-25 20:53 in BASIC Stamp
I have a awesome bot that uses a h-bridge that I made myself that consits or relays and a couple of transistors. Everything is perfect except for two things. I am using a ir remote control from a sony tv, so it has a quite limited range. When the bot gets out of range then ir does not receive the brake signal from the remote. Also when it loses the signal then it just keeps going eventually hitting a wall. I would use a contact sensor of some sort but it goes way to fast and is too heavy to stop from top speed to zero in under the distance of a foot. I also would use a ping sensor, but I am really tight on money, due to me spending it all on an 8800gt and q6600. I have no idea how to make the bs2 sense, that there was no signal for 100 ms, and therefor stop. I have the code here to make your lives esiaer. tongue.gif

' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word
irPulse VAR Word
remoteCode VAR Byte
t VAR Word
b VAR Word

LOW 12
LOW 13
LOW 14
LOW 15
PAUSE 100

start:
DO
GOSUB remote
GOSUB move
remoteCode = 15
LOOP




remote:                                           ' Main DO...LOOP

  Get_Pulses:                                ' Label to restart message check

  remoteCode = 0                             ' Clear previous remoteCode

  ' Wait for resting state between messages to end.

  DO
    RCTIME 9, 1, irPulse
  LOOP UNTIL irPulse > 1000

  ' Measure start pulse.  If out of range, then retry at Get_Pulses label.

  RCTIME 9, 0, irPulse
  IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Pulses

  ' Get Data bit pulses.

  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT0 = 1
  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT1 = 1
  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT2 = 1
  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT3 = 1
  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT4 = 1

  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT5 = 1
  RCTIME 9, 0, irPulse
  IF irPulse > 300 THEN remoteCode.BIT6 = 1

  ' Map digit keys to actual values.
  IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
  IF (remoteCode = 10) THEN remoteCode = 0
  DEBUG CLS, ? remoteCode
RETURN





backwardall:
HIGH 12
HIGH 13
HIGH 14
LOW 15
RETURN

forwardall:
HIGH 12
LOW 13
HIGH 15
HIGH 14
RETURN

goright:
HIGH 12
HIGH 13
LOW 15
LOW 14
PAUSE 100
RETURN

goleft:
HIGH 12
LOW 13
HIGH 15
LOW 14
PAUSE 100
RETURN

makelow:                                  ' brake
LOW 12
LOW 13
LOW 14
LOW 15
RETURN

light:
HIGH 0
PAUSE 100
RCTIME 0, 1, time
DEBUG HOME, " time = " ,DEC5 time
RETURN

move:
GOSUB makelow
IF remoteCode = 117 THEN
GOSUB backwardall
ENDIF
IF remoteCode = 116 THEN
GOSUB forwardall
ENDIF
IF remoteCode = 52 THEN
GOSUB goleft
ENDIF
IF remoteCode = 51 THEN
GOSUB goright
ENDIF
IF remoteCode = 101 THEN
GOSUB makelow
ENDIF
PAUSE 100
RETURN




The gosub makelow is the braking techique I use.

Comments

  • zemkaczzemkacz Posts: 19
    edited 2008-03-22 15:00
    Why no help? [noparse]:([/noparse]
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-22 15:05
    So, you are seeking advice on possibly extending the range of your I-R (by amplifying the sender's output or increasing the detector's sensitivity or both) or what?

    Post Edit -- sp.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-22 15:37
    First you have to figure out how your program can decide when the robot is out of range. Most remote controls don't send signals when you're not pressing a button and the robot can't tell if it's out of range or you're just not sending a command. One thing you could do is simply keep a count of the number of times you go through the DO / LOOP waiting for the resting state of the IR. If you loop too many times (you'll have to figure that out), then the robot stops. The idea is that you have to keep the movement button pushed on the remote. If you let go for more than roughly a second, the robot will stop.
  • zemkaczzemkacz Posts: 19
    edited 2008-03-22 17:49
    Well I am going towards the idea that Mike suggested, and well I have attempted that but I could use some help with that actually. Since the code for the ir key detection is whay my friend did, but sadly he is not online. So could you help me with modifying the code?
  • zemkaczzemkacz Posts: 19
    edited 2008-03-22 23:13
    Why is this that I have 40 views, yet only 4 people responded. One actually helped me a little and then that is it. Then I ask for a little help to change the code, and yet no one answers. Is this forum supposed to be an actual help instead of people answering with half *** answers?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-23 22:11
    I can't speak for anyone else, but I don't get paid for this and I have other things I do that take priority. I tend to answer people either because their question interests me, or I have a quick answer that I think will be helpful. Usually I respond to replies that imply that the other person has read my reply, done some thinking on what I said, and either has come up with another question and maybe some other data or part of an answer (which they communicate) and needs more or something that implies that they're doing some work and are invested in the process. There's always some give and take. Try describing what you tried based on my suggestion or at least restate what I described as you understand it. This is a support forum. Hopefully, people will learn something to the point where they can provide most of the answer that they want themselves. It doesn't always work that way, but that's the ideal.

    This is a written medium and sometimes things don't come across as well as they might verbally or in person. Some people sound a bit acerbic or sometimes "half assed" in this medium. Sometimes it's their sense of humor and sometimes it's because English is not their native language. You won't get much help if you call people names, particularly if you want something from them.

    Post Edited (Mike Green) : 3/23/2008 10:16:47 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-03-24 00:14
    The classic solution to this problem is to have the robot look look for a keypress every second or so, and STOP if it sees no keypress signal.

    This means you have to press the keys, or hold them down, to keep the robot in motion. This then becomes a problem if you have more than one robot, because two remotes will jam each other, if you hold a key down.

    But that's the classic solution.
  • ercoerco Posts: 20,260
    edited 2008-03-25 09:18
    Quickie alternate solution is an IR extender. All over eBay for cheap. I can't recommend a specific brand, but in general, they rebroadcast your IR signal around corners and through walls like a repeater station.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • ercoerco Posts: 20,260
    edited 2008-03-25 19:04
    Per my last post, now I'm interested in building an IR repeater or two. The basic idea is to extend the range of an IR remote by having one or more "slave" transmitters that
    rebroadcast whatever IR signal it detects. This is useful if you want to steer or get a signal to/from your robot around the corner, down the hallway, anywhere out of the·line of sight. A 38 kHz IR detector needs to be positioned towards the source (your handheld remote), then that triggers an LM555 circuit oscillating at 38 kHz to send the same received code to one or more IR LEDs aimed in a new direction (around·a corner or doorway). Obviously you don't want a feedback problem where the detector sees the same LEDs it's controlling, so you'll have to be careful about that. Minimally invasive wiring between detector & LEDs could be run on the wall around a corner, or around a doorjam. Alternatively, you could drill a small hole through a wall or ceilings·to route·the two or 3 small wires required. Clearly, you'd want to power this with an AC adapter, not batteries, so access to an outlet will figure in as well. Seems like you could daisy chain these together so A triggers B, B triggers C, etc. if the output signal is clean enough.

    Lots of·info on the web, but I'm going to start with http://www.cedarnet.org/smartware/Hardware/IR_Repeater/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-03-25 20:53
    Okay, but one of the first principles is: Don't build it if you can buy a finished solution at reasonable price.

    Radio Shack used to sell a pair of small pyramids -- a reciever that would take the IR-Remote signal, send it via RF to a second pyramid, which would then output a copy of the original IR-Signal. For about $25 for the pair. You can't really build anything that cheaply, that effectively.

    At the very least, buy a pair and use them as a prototype to check out the concept.
Sign In or Register to comment.