To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1543
1542  |  1544
Special: 
[DAT] (requires LDraw-compatible viewer)
Subject: 
Re: Yet another NQC spybot API submission
Newsgroups: 
lugnet.robotics.rcx.nqc, lugnet.robotics.spybotics
Date: 
Fri, 17 Oct 2003 12:26:03 GMT
Viewed: 
10195 times
  
Doh!  I had the low and high bytes switched on the items below which can be
passed one or more frequencies.  Now I have actually tested this code and it
does, indeed, work (with the low and high bytes in the correct order).  I've
also slightly changed the 3 preprocessor macros below which take no parameters.
Now they look like functions rather than constants.  And, lastly, I changed the
name of the GateOn macro to be just Gate (to match the MindScript "gate" command
name more closely).

I'm working on some of the other Spybot features (eeprom, find world, etc) and
should have something shortly.  I'd like to gauge interest regarding NQC and
Spybotics.  Anybody out there still trying to use these programmable bricks?
I'd like to more fully support the Spybot in BricxCC but I'm not sure how much
effort they are worth if nobody is interested.  Of course, I'd also like to get
pbForth and leJOS support up to par, and ... a million other things.

// --- start of spy.nqh additions ---

#define SOUNDEFFECT __res 2

#define Gate(o, p) 0x62, p, o
#define GateOff() 0x70
#define Glide(s, p, t) 0x45, t, s & 0xFF, s >> 8, p & 0xFF, p >> 8
#define Vibrato(s, p, t) 0x55, t, s & 0xFF, s >> 8, p & 0xFF, p >> 8
#define WaitEffect(t) 0x21, t
#define FixedWaitEffect(t) 0x81, t
#define Tone(f, t) 0x33, t, f & 0xFF, f >> 8
#define FixedTone(f, t) 0x93, t, f & 0xFF, f >> 8
#define RepeatEffect() 0x10

#define AnimateLED(f, t) f, t
#define RepeatAnimation() 0xFF, 0

#define EffectSound() @(0x350000) // Sound Effects control registers (0,1)
#define EffectTime() @(0x350001)

__nolist void SetEffectSound(const int &s) { Set(EffectSound(), s); }
__nolist void SetEffectTime(const int &t) { Set(EffectTime(), t); }

// --- end of spy.nqh additions ---

And here is a sample NQC program demonstrating the use of these Spybotics API
definitions:

#include "spy.nqh"

SOUNDEFFECT my_effect {
  Gate(1, 10),
  Glide(294, 660, 60),  // testing
  GateOff()//,
//  RepeatEffect()
};

SOUNDEFFECT trill {
  Gate(1, 10),
  Tone(1000, 50),
  Gate(1, 5),
  Tone(2000, 50),
  RepeatEffect()
};

SOUNDEFFECT beep {
  Tone(440, 50),
  WaitEffect(50),
  FixedTone(880, 50)
};

ANIMATION my_animation {
  AnimateLED(nLedRed1, 50),
  AnimateLED(nLedRed2, 50),
  AnimateLED(nLedRed3, 50),
  AnimateLED(nLedRed2, 50),
  RepeatAnimation()
};

ANIMATION animation2 {
  AnimateLED(nLedRed1, 10),
  AnimateLED(nLedRed2, 10),
  AnimateLED(nLedRed3, 10),
  AnimateLED(nLedRed2, 10)
};

task main()
{
  SetAnimation(my_animation);
  PlaySound(my_effect);
  Wait(200);
  PlaySound(trill);
  Wait(200);
  SetEffectSound(100);
  PlaySound(beep); Wait(200);
  SetEffectSound(200);
  PlaySound(beep); Wait(200);
//  SetAnimation(animation2);
}

The documentation on Dave's website regarding the ANIMATION resource is slightly
incorrect.  He writes:

An animation declaration looks like this:

ANIMATION name = { data ... };

The = sign will cause an NQC parse error.  This should be

ANIMATION name { data ... };

Later he writes:

A pair of 0,0 ends the animation. A pair of 255,255 causes the animation to loop
continuously.

Based on the code generated by the LEGO MindScript/LASM compiler the 0,0 is not
needed to end an animation and to loop continuously you use 255, 0.  In
Mindscript you define an LED animation like this:

  led ScanUp { forever {
    led cRed1 for 10
    led cRed2 for 10
    led cRed3 for 10
    }
  }

  led ScanDown {
    led cRed3 for 10
    led cRed2 for 10
    led cRed1 for 10
  }

This compiles to LASM as you see here:

mood 8
1 10
2 10
4 10
255 0
endm
;----------------------------------------
;LED ScanUp (display 8), size: 8 bytes
;----------------------------------------
mood 9
1 10
2 10
4 10
endm
;----------------------------------------
;LED ScanDown (display 9), size: 6 bytes

Using my Spybotics API submission you can now define your LED animations in a
manner very similar to MindScript:

ANIMATION ScanUp {
  AnimateLED(nLedRed1, 10),
  AnimateLED(nLedRed2, 10),
  AnimateLED(nLedRed3, 10),
  RepeatAnimation()
};

ANIMATION ScanDown {
  AnimateLED(nLedRed1, 10),
  AnimateLED(nLedRed2, 10),
  AnimateLED(nLedRed3, 10)
};

The NQC compiler generates:

*** Animation 8 = ScanUp
000  01 0a 02 0a 04 0a ff 00

*** Animation 9 = ScanDown
000  01 0a 02 0a 04 0a


For sound effects the MindScript code looks like:

  fx beep { forever {
    gate 1 in 10
    glide 294..660 for 60
    gate off
    wait 255
    vibrato 294..660 for 60
    fixed wait 100
    fixed tone 500 for 50
    tone 300 for 50  }
  }

This compiles to the following LASM code:

sound 64
startg 10,1
freqs 60,294,660
stopg
pauses 255
freqv 60,294,660
pausef 100
tonef 50,500
tones 50,300
repeats
ends
;----------------------------------------
;Fx beep (sound 64), size: 29 bytes

In NQC (using the above additions to spy.nqh) you would write:

SOUNDEFFECT beep {
  Gate(1, 10),
  Glide(294, 660, 60),
  GateOff(),
  WaitEffect(255),
  Vibrato(294, 660, 60),
  FixedWaitEffect(100),
  FixedTone(500, 50),
  Tone(300, 50),
  RepeatEffect()
};

which compiles to:

*** Res 2 64 = beep
000  62 0a 01 45 3c 26 01 94 02 70 21 ff 55 3c 26 01
00d  94 02 81 64 93 32 f4 01 33 32 2c 01 10



Message has 2 Replies:
  Re: Yet another NQC spybot API submission
 
I'm hanging on every byte, John. I've tried a couple times to do what your doing with the Spybot API, and I just don't seem to have what it takes. For instance, I tried to figure out how to get the Spybot to respond to its remote control from NQC, (...) (21 years ago, 17-Oct-03, to lugnet.robotics.rcx.nqc, lugnet.robotics.spybotics)
  Re: Yet another NQC spybot API submission
 
(...) Hello John, Sure I'm interested... Though I have not devoted enough time to the Spybots, I think they make a good "poor man" robotics platform - unfortunately with quite a few limitations. Thanks a lot for the time and energy you put in (...) (21 years ago, 17-Oct-03, to lugnet.robotics.rcx.nqc, lugnet.robotics.spybotics)

Message is in Reply To:
  Yet another NQC spybot API submission
 
Here is another submission to the NQC spybot API. I haven't properly tested this against an actual Spybot but I have compared the NQC output code to what is generated by MindScript and documented in the VPB help file. #define SOUNDEFFECT __res 2 (...) (21 years ago, 16-Oct-03, to lugnet.robotics.rcx.nqc)

6 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR