Shop OBEX P1 Docs P2 Docs Learn Events
Question for Erco — Parallax Forums

Question for Erco

neerdowellneerdowell Posts: 25
edited 2011-11-19 05:28 in Robotics
Erco, I saw a video you posted but now I can't find it again. It was using the blue scribbler and I think you called it something like "object following". You held your hand in front of the robot and it stopped; you moved your hand left and right and the robot turned in that direction. You moved your hand toward the robot and the robot went in reverse, away from your hand. You moved your hand away from the robot and it moved forward to follow your hand.

My question: do you have the scribbler 2 GUI file for that example? I think it was pretty cool and I'd like to use it during a demo.

Comments

  • ercoerco Posts: 20,255
    edited 2011-11-16 17:39
    I did not GUI it for S2, but it should be easy enough if you want to do it. The PBasic code was simplicity itself, even listed on the Youtube site:

    http://www.youtube.com/watch?v=_M4sPnuu37U

    a:FREQOUT 14,1,38500
    B0=IN6
    LOW 14
    FREQOUT 15,1,38500
    B1=IN6
    LOW 15
    IF B0=0 THEN PULSOUT 12,1600
    IF B0=1 THEN PULSOUT 12,2400
    IF B1=0 THEN PULSOUT 13,1600
    IF B1=1 THEN PULSOUT 13,2400
    GOTO a

    Scribbler has undergeared motors, so there's a lot of lag and overshoot, which limits the tracking speed. S2 supposedly has more powerful motors, so it may be able to track at higher speed.Let us know how you do!
  • neerdowellneerdowell Posts: 25
    edited 2011-11-16 17:57
    Yeah, that was the one I saw.

    I'm going to try to do this on the S2, but I'm really a newbie and have no experience with the BASIC stamp. I see that FREQUOT activates the speaker, but I didn't notice any sound on the video except the sound of the motors. I see that PULSOUT turns the wheels, but I haven't done any programs yet involving the IR sensors, so it's going to take me awhile to come up to speed on this. If anyone wants to take a stab at this and post the results, I would appreciate it as I try to learn it myself.

    Thanks Erco.
    Don
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-11-17 00:56
    Don,

    I'm not sure if you realize the S2 uses a Propeller while erco's code is for a Basic Stamp used by the S1. If you look in the OBEX for BS2_Functions, you'll see how to translate erco's code to Propellerese (aka Spin).
  • neerdowellneerdowell Posts: 25
    edited 2011-11-17 02:34
    Duane Degn wrote: »
    Don,

    I'm not sure if you realize the S2 uses a Propeller while erco's code is for a Basic Stamp used by the S1. If you look in the OBEX for BS2_Functions, you'll see how to translate erco's code to Propellerese (aka Spin).

    OK, thanks Duane, I wasn't aware of that resource. Yes, I did know that S2 is propeller-based while S1 is Basic Stamp-based.

    I see how BS2_Functions allows you to essentially convert Basic Stamp commands to Spin code. I'm just starting out with S2, using the GUI, and I'm preparing to teach my middle school students something about programming by using the S2. I want to start out with just the GUI this year, and maybe next year get into Spin, so what I really had in mind here is the GUI equivalent of Erco's Basic Stamp code. I started that last night and was able to get the robot to turn left or right based on seeing an object either with the left or right IR sensor, but now I need to figure out how to make it go forward (or backward) to "follow" the object. I've only had the S2 for a few weeks now, so I'm trying to learn the tricks of how it works.

    Thanks for pointing me to that resource.

    Don
  • ercoerco Posts: 20,255
    edited 2011-11-17 08:32
    neerdowell wrote: »
    I started that last night and was able to get the robot to turn left or right based on seeing an object either with the left or right IR sensor, but now I need to figure out how to make it go forward (or backward) to "follow" the object.
    Don

    Don: Great job, you're almost done then! All my program does is test each two IR sensors and drive the wheels forward or backward accordingly:

    Left wheel drives reverse if left IR sensor detects anything, drives forward if nothing detected.
    Right wheel drives reverse if right IR sensor detects anything, drives forward if nothing detected.
    Lather
    Rinse
    Repeat!

    :)

    I experimented and selected one wheel speed (same forward and reverse) for best tracking.
  • neerdowellneerdowell Posts: 25
    edited 2011-11-17 09:12
    Erco, thanks, that's great info. Attached is what I've got so far. The results are not good yet, it just keeps chugging forward, sometimes turning if it sees an obstacle, sometimes not. It never backs away from my hand, tries to run right through it.

    So many variables here: how many consecutive times does it need to see the object, what speed to use (I've tried 100, 50, and 20 and none seem to be ideal), when I set the speed of the left and right wheels, do I need to provide a time?

    I'll keep plugging away.

    Thanks for your help.

    Don
  • neerdowellneerdowell Posts: 25
    edited 2011-11-17 12:42
    I think the reason I am not getting satisfactory results is that I need to test for 4 possibilities within the loop (and I'm not doing that now):

    1. no obstacles reported on either IR sensor
    2. obstacle reported on both sensors
    3. obstacle reported on the left sensor only
    4. obstacle reported on the right sensor only

    I know how to test for these 4 cases, what I don't know is what to do in each case in terms of wheel movement. And when the obstacle gets too close to the robot, the robot needs to move backwards. I don't know how to test for that condition, unless it involves how many consecutive times the obstacle must be observed in order for it to be true.

    I'd appreciate any enlightenment here. Thanks.
  • neerdowellneerdowell Posts: 25
    edited 2011-11-17 15:54
    Well, this works "somewhat". It's nowhere near as good as Erco's S1, and sometimes it turns right when it should turn left, and vice versa. I think there is either something missing or something I am doing wrong, probably both.
  • WhitWhit Posts: 4,191
    edited 2011-11-17 18:28
    @erco - When did you do this and how did I miss it? Cool code!

    @neerdowell - great project converting this to the S2, I will check it out...
  • neerdowellneerdowell Posts: 25
    edited 2011-11-17 18:57
    This seems to work somewhat better. This is a real learning process!

    Don
  • ercoerco Posts: 20,255
    edited 2011-11-17 19:46
    Don: I can't get to my S2 right now, but it sounds like you're doing a great job of picking up the GUI. Fantastic!
  • neerdowellneerdowell Posts: 25
    edited 2011-11-18 01:36
    Thanks Erco. Attached is a version (4) that works pretty well, it seems to me. I realized that I wasn't adjusting BOTH wheels during a turn, so the last and previous versions were not really reacting well to the turns. I think this pretty much fixes it.

    This has been a fun learning experience. Thanks for your great example with S1.

    Don
  • neerdowellneerdowell Posts: 25
    edited 2011-11-18 04:49
    Has anyone noticed a bug in the forum software? The post above has the word BOTH twice, but I only typed it once. That happened in another post also. It seems to sometimes happen at the end of a line. Strange.
  • WhitWhit Posts: 4,191
    edited 2011-11-18 06:50
    @neerdowell - attached for you to try - just for a little feed-back - I haven't run this yet. I am at work. The LEDs may be on and off so fast that it won't work. Have fun!
  • ercoerco Posts: 20,255
    edited 2011-11-18 08:59
    neerdowell wrote: »
    Has anyone noticed a bug in the forum software? The post above has the word BOTH twice, but I only typed it once. That happened in another post also. It seems to sometimes happen at the end of a line. Strange.

    Yes, I also see see see see that pretty often. :)

    It does happen at the end of a line.
  • ercoerco Posts: 20,255
    edited 2011-11-18 09:01
    PS: My S2 is disassembled in pieces right now. But it will be like a Phoenix, rising from Arizona... (Frank Costanza)
  • neerdowellneerdowell Posts: 25
    edited 2011-11-18 10:14
    @whit - Yeah, I tried that one and it works. The LEDs do flash pretty quickly, as you thought. But it does show you how the sensors are working, and that may help in making finer adjustments to the routine. Thanks. Don
  • neerdowellneerdowell Posts: 25
    edited 2011-11-19 05:28
    I've noticed that changing the turning rate from 50 to 25 seems to induce less "stress" on the robot, and it seems to track a bit better.
Sign In or Register to comment.