Subject:
|
How can I reach world related info from Spybotic
|
Newsgroups:
|
lugnet.robotics.spybotics
|
Date:
|
Tue, 4 Mar 2003 18:17:33 GMT
|
Viewed:
|
7529 times
|
| |
 | |
Hello all !
I am still busy with finishing the NQC API for the Spybots.
After the last info from John I tought I understand it all. But I am still
confused how things work exactly !
When I place the controller away from the bot what syntax do I have to use
to get the distance (zones...) and the direction..
While (true)
distance = ..........
direction = ......
Whend
Do I have to set things as well ?
Included the latest version of the NQC API
//API Spybotics to program in NQC/BrickCC
//Mark Ferris,John Hansen,André Koopman
#define LED_MODE_ON 0
#define LED_MODE_BLINK 1
#define LED_MODE_DURATION 2
#define LED_MODE_SCALE 3
#define LED_MODE_SCALE_BLINK 4
#define LED_MODE_SCALE_DURATION 5
#define LED_MODE_RED_SCALE 6
#define LED_MODE_RED_SCALE_BLINK 7
#define LED_MODE_GREEN_SCALE 8
#define LED_MODE_GREEN_SCALE_BLINK 9
#define LED_MODE_YELLOW 10
#define LED_MODE_YELLOW_BLINK 11
#define LED_MODE_YELLOW_DURATION 12
#define LED_MODE_VLL 13
#define LED_MODE_VLL_BLINK 14
#define LED_MODE_VLL_DURATION 15
// ROM animations (for the front LEDs)
#define ANIMATION_SCAN 0
#define ANIMATION_SPARKLE 1
#define ANIMATION_FLASH 2
#define ANIMATION_RED_TO_GREEN 3
#define ANIMATION_GREEN_TO_RED 4
#define ANIMATION_POINT_FORWARD 5
#define ANIMATION_ALARM 6
#define ANIMATION_THINKING 7
#define NO_TARGET 255
#define NO_ID 0
#define CONTROLLERID1 1
#define CONTROLLERID2 2
#define CONTROLLERID3 3
#define CONTROLLERID4 4
#define CONTROLLERID5 5
#define CONTROLLERID6 6
#define PCID 7
#define MIN_BOTID 8
#define MAX_BOTID 255
#define RANGE_NOWHERE 0
#define RANGE_ANYWHERE 1
#define RANGE_THERE 2
#define RANGE_HERE 3
#define DIRECTION_LEFT 0
#define DIRECTION_LEFTOFCENTER 1
#define DIRECTION_CENTER 2
#define DIRECTION_RIGHTOFCENTER 3
#define DIRECTION_RIGHT 4
#define ASPECT_FRONTLEFT 0
#define ASPECT_FRONT 1
#define ASPECT_FRONTRIGHT 2
#define ASPECT_BACKRIGHT 3
#define ASPECT_BACK 4
#define ASPECT_BACKLEFT 5
#define SPY_SHORTID 7
#define SPY_LINKID 2
#define SPY_RANGE 3
#define SPY_DIRECTION 4
#define SPY_ASPECT 5
#define SPY_INFO 6
#define SPY_NOTE 1
#define SPY_TARGETID 0
#define Target(n) @(0x320000 + n)
#define LED(n) @(0x160000 + (n)) // LED control registers
// LED's may be set/checked manually
__nolist void SetLED(const int mode, const int &v)
{ Set(LED(mode), v); }
//Get Target
__nolist void GetTarget(const int n, int &v)
{
asm { 0x14, &v : __ASM_NO_TYPE + __ASM_SMALL_VALUE, 0x32, n, 0x00 };
}
//Set Target ID
__nolist void SetTargetID(const int &v)
{ Set(Target(SPY_TARGETID), v); }
//Set Target Note
__nolist void SetTargetNote(const int &v)
{ Set(Target(SPY_NOTE), v); }
//Get world
__nolist void GetWorld(const int n, int &t, int &v)
{
asm { 0x14, &v : __ASM_NO_TYPE + __ASM_SMALL_VALUE, 0x2a + n,
&t : __ASM_NO_TYPE + __ASM_SMALL_VALUE, 0x00 };
}
//Get world shortID
__nolist void GetWorldShortID(int &t, int &v)
{ GetWorld(SPY_SHORTID, t, v); }
//Get world link ID
__nolist void GetWorldLinkID(int &t, int &v)
{ GetWorld(SPY_LINKID, t, v); }
//Get world range
__nolist void GetWorldRange(int &t, int &v)
{ GetWorld(SPY_RANGE, t, v); }
//Get world direction
__nolist void GetWorldDirection(int &t, int &v)
{ GetWorld(SPY_DIRECTION,t, v); }
//Get world aspect
__nolist void GetWorldAspect(int &t, int &v)
{ GetWorld(SPY_ASPECT, t, v); }
//Get world note
__nolist void GetWorldNote(int &t, int &v)
{ GetWorld(SPY_NOTE, t, v); }
//Set world note
__nolist void SetWorldNote(int &t, const int &v)
{
asm { 0x05, 0x2b, &t : __ASM_NO_TYPE + __ASM_SMALL_VALUE, &v};
}
#if defined(__SPY)
// Initialises the engine
__nolist void MainSub()
{
asm { 0x17, 0 };
}
// Resets the engine
__nolist void ResetEngine()
{
asm { 0x17, 11 };
}
// Select target
__nolist void SelectTarget()
{
asm { 0x17, 16 };
}
// Update display for radar and proximity modes
__nolist void UpdateDisplayTarget()
{
asm { 0x17, 17 };
}
// Update display for game time remaining modes
__nolist void UpdateDisplayTick()
{
asm { 0x17, 19 };
}
// Sends an RCX PBMessage to RCX or Scout
// nMessage = 1 - 255
__nolist void SendRCXMessage (const int nMessage)
{
asm { 0xe3, &nMessage };
asm { 0x17, 37 };
asm { 0x01, 1 };
}
// defines for LedAnimation
#define displayLedNone -1
#define displayLedScan 0
#define displayLedSparkle 1
#define displayLedFlash 2
#define displayLedRedToGreen 3
#define displayLedGreenToRed 4
#define displayLedPointForward 5
#define displayLedAlarm 6
#define displayLedThinking 7
__nolist void Disp (const int display)
{
asm { 0xe3, &display } ;
asm { 0x17, 42 };
asm { 0x01, 1 };
}
// defines for move
#define moveForward 0x0101
#define moveBackward 0x0102
#define moveSpinLeft 0x0103
#define moveSpinRight 0x0104
#define moveTurnLeft 0x0105
#define moveTurnRight 0x0106
#define moveAvoidLeft 0x0107
#define moveAvoidRight 0x0108
#define moveRest 0x0109
#define moveStop 0x010a
// time is in 10ms steps
__nolist void BasicMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 43 };
asm { 0x01, 2 };
}
// nSound is 0-79, -1 = no sound
// nDisplay is LED animation (0-15) to play, -1 = no animation
// nMovement is from the *Move routines defined below, -1 = no move
// nRepeat is number of times to repeat motion
// ntime is in 10ms steps
__nolist void Action (const int nSound, const int nDisplay,
const int nMovement, const int nRepeat,
const int nTime)
{
asm { 0xe3, &nSound };
asm { 0xe3, &nDisplay };
asm { 0xe3, &nMovement };
asm { 0xe3, &nRepeat };
asm { 0xe3, &nTime };
asm { 0x17, 44 };
asm { 0x01, 5 };
}
// defines for move
#define moveRandomForward 0x0201
#define moveRandomBackward 0x0202
#define moveRandomSpinLeft 0x0203
#define moveRandomSpinRight 0x0204
#define moveRandomTurnLeft 0x0205
#define moveRandomTurnRight 0x0206
#define moveRandomRest 0x0207
// time is in 10ms steps
__nolist void RandomMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 46 };
asm { 0x01, 2 };
}
// defines for move
#define moveZigZag 0x0301
#define moveShake 0x0302
#define moveScan 0x0303
#define moveStep 0x0304
#define moveStepBack 0x0305
#define moveSearch 0x0306
#define moveFakeLeft 0x0307
#define moveRakeRight 0x0308
#define moveBugForward 0x0309
#define moveLazy 0x030a
#define moveWalk 0x030b
#define moveWalkBack 0x030c
#define moveDance 0x030d
// time is in 10ms steps
__nolist void FancyMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 47 };
asm { 0x01, 2 };
}
// defines for move
#define moveForwardSlowDown 0x0401
#define moveBackwardSlowDown 0x0402
#define moveSpinLeftSlowDown 0x0403
#define moveSpinRightSlowDown 0x0204
// time is in 10ms steps
__nolist void SlowDownMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 48 };
asm { 0x01, 2 };
}
// defines for move
#define moveForwardSpeedUp 0x0501
#define moveBackwardSpeedUp 0x0502
#define moveSpinLeftSpeedUp 0x0503
#define moveSpinRightSpeedUp 0x0504
// time is in 10ms steps
__nolist void SpeedUpMove (const int move, const int time)
{
asm { 0xe3, &move };
asm { 0xe3, &time };
asm { 0x17, 49 };
asm { 0x01, 2 };
}
// Adds a value to a 2 byte location in EEprom
__nolist void Sum2Mem (const int nMem, const int nValue)
{
asm { 0xe3, &nMem };
asm { 0xe3, &nValue };
asm { 0x17, 50 };
asm { 0x01, 2 };
}
// Adds a value to a 4 byte location in EEprom
__nolist void Sum4Mem (const int nMem, const int nValue)
{
asm { 0xe3, &nMem };
asm { 0xe3, &nValue };
asm { 0x17, 51 };
asm { 0x01, 2 };
}
// Queues a request for the engine to chance the game state
// defines for nNewState
#define GameOverState -1
#define OutOfGameState -2
#define StartState 0
__nolist void Goto_Bead (const int nNewState)
{
asm { 0xe3, &nNewState};
asm { 0x17, 65 };
asm { 0x01, 1 };
}
// Basic movement like sub 43 Basic_Move
// time is in 10ms steps
__nolist void BasicMovement_Bead (const int nMovement, const int nTime)
{
asm { 0xe3, &nMovement};
asm { 0xe3, &nTime};
asm { 0x17, 87 };
asm { 0x01, 2 };
}
//Set Bot property parameters
//Like Game
Mode,Speed,TargetType,TargetTypeID,TargetTypeNote,EnableStatus,DisAbleStatus
//SusspendStateBeads,ResuseStateBeads,DisplayMode,RCDisable,RCChannel,TargetNote
//defines nProperty parameters
#define setGameMode 0
#define setSpeed 1
#define setVisibility 2
#define setTargetType 3
#define setTargetTypeID 4
#define setTargetTeamTypeID 5
#define setTargetTypeNote 6
#define setEnableStatus 7
#define setDisableStatus 8
#define setSuspendStateBeads 9
#define setResumeStateBeads 10
#define setDisplayMode 11
#define setRCDisable 12
#define setRCChannel 13
#define setTargetNote 14
//defines nValue parameters
#define SlowSpeed 1
#define NormalSpeed 2
#define FastSpeed 3
#define StealthVisibility 0
#define LowVisibility 1
#define NormalVisibility 2
#define HighVisibility 3
#define StateTarget -1
#define Nothing 0
#define Anything 1
#define AnyController 2
#define AnyBot 3
#define MyController 4
#define NotMyController 5
__nolist void Set_Bead(const int nProperty, const int nVal)
{
asm { 0xe3, &nProperty } ;
asm { 0xe3, &nVal } ;
asm { 0x17, 88 };
asm { 0x01, 2 };
}
//Play a tone for 100mSec
__nolist void PlayTone_Bead(const int nTone)
{
asm { 0xe3, &nTone } ;
asm { 0x17, 93 };
asm { 0x01, 1 };
}
// Play's a sound in 10mSec time steps
// Defines for nSound
//sound effects (0 to 79)-1 no sound
#define nSoundNone -1
#define nSoundKeyPressSound 0
#define nSoundPowerOn 1
#define nSoundSweepDown 2
#define nSoundSweepUp 3
#define nSoundBuh 4
#define nSoundHurrah 5
#define nSoundShocked 6
#define nSoundFireLaser 7
#define nSoundFireElectroNet 8
#define nSoundFireSpinner 9
#define nSoundHitByLaser 10
#define nSoundHitByElectroNet 11
#define nSoundHitBySpinner 12
#define nSoundTag 13
#define nSoundCrash 14
#define nSoundFight 15
#define nSoundGotIt 16
#define nSoundGeneralAlert 17
#define nSoundOutOfEnergyAlert 18
#define nSoundLowEnergyAlert 19
#define nSoundScoreAlert 20
#define nSoundTimeAlert 21
#define nSoundProximityAlert 22
#define nSoundDangerAlert 23
#define nSoundBombAlert 24
#define nSoundFinalCountdown 25
#define nSoundTickTock 26
#define nSoundGoto 27
#define nSoundScan 28
#define nSoundPointTo 29
#define nSoundActivateShields 30 //0.75 seconds
#define nSoundActivateReflect 31 //0.79 seconds
#define nSoundActivateCloak 32 //1.81 seconds
#define nSoundActivateFlashBlind 33 //0.95 seconds
#define nSoundMagnet 34 //5.88 seconds
#define nSoundQuadDamage 35 //2.26 seconds
#define nSoundRepulse 36 //5.2 seconds
#define nSoundTurbo 37 //2.4 seconds
#define nSoundFreeze 38 //4.8 seconds
#define nSoundSlow 39 //2.9 seconds
#define nSoundReverse 40 //4.9 seconds
#define nSoundDizzy 41 //5.4 seconds
#define nSoundBoost 42 //2.28 seconds
#define nSoundDeactivateShields 43 //1.05 seconds
#define nSoundDeactivateReflect 44 //0.3 seconds
#define nSoundDeactivateCloak 45 //1.1 seconds
#define nSoundReflect 46
#define nSoundExplosion 47
#define nSoundBigExplosion 48
#define nSoundPlaceBomb 49
#define nSoundHitByWind 50
#define nSoundOuch 51
#define nSoundGeiger 52
#define nSoundWhistle 53
#define nSoundImIt 54
#define nSoundHelp 55
#define nSoundSiren 56
#define nSoundBurnt 57
#define nSoundGrinded 58
#define nSoundSmacked 59
#define nSoundTrillUp 60
#define nSoundTrillDown 61
#define nSoundYell 62
#define nSoundWhisper 63
//sounds in e2prom
#define nSoundSpeciesStart 64
#define nSoundWin 65
#define nSoundLose 66
#define nSoundOutOfGame 67
#define nSoundMissionStart 68
#define nSoundMission1 69
#define nSoundMission2 70
#define nSoundMission3 71
#define nSoundMission4 72
#define nSoundMission5 73
#define nSoundUser1 74
#define nSoundUser2 75
#define nSoundUser3 76
#define nSoundUser4 77
#define nSoundUser5 78
#define nSoundUser6 79
__nolist void PlaySound_Bead(const int nSound, const int nTime)
{
asm { 0xe3, &nSound };
asm { 0xe3, &nTime };
asm { 0x17, 94 };
asm { 0x01, 2 };
}
// Defines for WichLed(s)
#define nLedRed1 0x01
#define nLedRed2 0x02
#define nLedRed3 0x04
#define nLedGreen1 0x08
#define nLedGreen2 0x10
#define nLedGreen3 0x20
#define nLedYellow 0x40
#define nLedRedGreenLEDs
nLedRed1+nLedRed2+nLedRed3+nLedGreen1+nLedGreen2+nLedGreen3
__nolist void LED_Bead(const int nLED,const int nBlink,const int
nInterval,const int nTime)
{
asm { 0xe3, &nLED } ;
asm { 0xe3, &nBlink } ;
asm { 0xe3, &nInterval } ;
asm { 0xe3, &nTime } ;
asm { 0x17, 95 };
asm { 0x01, 4 };
}
// Defines for What to display
#define nDisplayState 1
#define nDisplayRandom 2
#define nDisplayNothing 3
#define nDisplayVars 0x10
#define nDisplayOneVar nDisplayVars + 1
#define nDisplayTwoVar nDisplayVars + 2
#define nDisplayGameTimeRemaining nDisplayVars + 3
#define nDisplayTarget 0x20
#define nDisplayRadar nDisplayTarget + 1
#define nDisplayProximity nDisplayTarget + 2
#define nDisplayAnimation 0x30 //uses 0x30 to 0x3f
__nolist void Display_Bead(const int nDisplay,const int nTime)
{
asm { 0xe3, &nDisplay } ;
asm { 0xe3, &nTime } ;
asm { 0x17, 96 };
asm { 0x01, 2 };
}
// Defines direction Led count
#define nDirDown 0
#define nDirUp 1
__nolist void CountDown_Bead(const int nCount,const int nDir,const int nStep)
{
asm { 0xe3, &nCount } ;
asm { 0xe3, &nDir } ;
asm { 0xe3, &nStep } ;
asm { 0x17, 97 };
asm { 0x01, 3 };
}
// Drives The Spybot forward until it hit something or time elapses
__nolist void Bump_Bead(const int nTime)
{
asm { 0xe3, &nTime };
asm { 0x17, 100 };
asm { 0x01, 1 };
}
// Fancy movement like sub 47 with extra nRepeat
// time is in 10ms steps
__nolist void FancyMovement_Bead (const int move, const int nRepeat, const
int time)
{
asm { 0xe3, &move };
asm { 0xe3, &nRepeat };
asm { 0xe3, &time };
asm { 0x17, 109 };
asm { 0x01, 3 };
}
// Wait in 10mSec steps
__nolist void Wait_Bead(const int nTime)
{
asm { 0xe3, &nTime } ;
asm { 0x17, 113 };
asm { 0x01, 1 };
}
// Initialises the game
__nolist void InitGame()
{
asm { 0x17, 128 };
}
// Bumper aktie
__nolist void BumpAction()
{
asm { 0x17, 140 };
}
#endif
|
|
Message has 2 Replies:  | | Spybotic API - MacNQC, programmer's guide?
|
| (...) And first, thank you (& Mark, John, and others) for figuring all this out! I'm trying to program a Spybot using NQC (via the MacNQC GUI), and without support like this & Dave's NQC, I'd never get anywhere. Again, THANK YOU to the community. (...) (21 years ago, 4-Apr-04, to lugnet.robotics.spybotics)
|
5 Messages in This Thread:   
      
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|