|
Some slight revisions to the previous submission. And now I have finally
figured out how to get the Spybot to control Manas. I'm very puzzled by the
equations for setting the output bytes. Any explanations would be greatly
appreciated.
#include "spy.nqh"
#define MANAS_ALL 4
#define MANAS_1 5
#define MANAS_2 6
#define MANAS_3 7
#define EM_FLOAT 0
#define EM_OFF 8
#define EM_FWD 7
#define EM_REV 15
int em1,em2,em3,em4,em5,em6; //Global motor control locations
task main()
{
SetPingInterval(0);
// This demo starts the manas comms task, then loops forever.
// In the loop, it steps through three control phases setting
// the motors to off, and then paired forward and reverse.
start manas;
while (true)
{
em1=EM_OFF;
em2=EM_OFF;
em3=EM_OFF;
em4=EM_OFF;
em5=EM_OFF;
em6=EM_OFF;
Wait(100);
em1=EM_FWD;
em2=EM_REV;
em3=EM_FWD;
em4=EM_REV;
em5=EM_FWD;
em6=EM_REV;
Wait(100);
em1=EM_FLOAT;
em2=EM_FLOAT;
em3=EM_FLOAT;
em4=EM_FLOAT;
em5=EM_FLOAT;
em6=EM_FLOAT;
Wait(100);
em1=EM_REV;
em2=EM_FWD;
em3=EM_REV;
em4=EM_FWD;
em5=EM_REV;
em6=EM_FWD;
Wait(100);
}
}
// The manas task continuously resends the motor settings.
// When the RCX is halted, this task stops and the manas
// motors automatically shut off
task manas()
{
SetTxType(TX_TYPE_USER);
SetTxBaud(TX_BAUD_4800);
SetTxDirection(TX_DIRECTION_FRONT_LEFT);
while (true)
{
// SetTxUserChecksum(TX_USER_NO_CHECKSUM);
// SetTxUserBiPhase(TX_USER_NO_BIPHASE);
// SetTxUserPreamblePos(0);
// SetTxUserPreambleLen(0);
// SetSerialData(0,0x6f);
// SetSerialData(1,0x0b);
// SendSerial(0,2);
// em1 = 0;
/*
// Set the first unit two message bytes and send them
SetSerialData(0,(RC_CHANNEL_BROADCAST+4)*16+em1);
SetSerialData(1,em2*16+16-(((RC_CHANNEL_BROADCAST+4)+em1+em2) & 16));
SendSerial(0,2);
*/
// Set the first unit two message bytes and send them
SetSerialData(0,MANAS_1*0x10+em1);
SetSerialData(1,em2*0x10+0x10-((MANAS_1+em1+em2)&0xf));
SendSerial(0,2);
// Set the second unit two message bytes and send them
SetSerialData(0,MANAS_2*0x10+em3);
SetSerialData(1,em4*0x10+0x10-((MANAS_2+em3+em4)&0xf));
SendSerial(0,2);
// Set the third unit two message bytes and send them
SetSerialData(0,MANAS_3*0x10+em5);
SetSerialData(1,em6*0x10+0x10-((MANAS_3+em5+em6)&0xf));
SendSerial(0,2);
// Delay for a while so we can resend them regularly
Wait(10);
}
}
// -- cut here for spy.nqc additions ---
#define Stack(n) @(0x120000 + (n))
__nolist void Push(const int v) { asm { 0xe3, v }; }
__nolist void Pop(const int n) { asm { 0x01, n }; }
__nolist void SetStack(const int i, const int &v) { Set(Stack(i), v); }
#define TIMER_RUNNING 1
#define TIMER_STOPPED 0
#define TimerState(n) @(0x130000 + (n))
__nolist void SetTimerState(const int n, const int s) { Set(TimerState(n), s);
}
#define EEPROM(n) @(0x140000 + (n))
__nolist void SetEEPROM(const int i, const int &d) { Set(EEPROM(i), d); }
#define CurrentTaskID() @(0x200000)
#define SerialData(n) @(0x210000 + (n)) // data for SendSerial
__nolist void SetSerialData(const int n, const int &v) { Set(SerialData(n), v);
}
#define TX_TYPE_SPYBOT 0
#define TX_TYPE_RCX 1
#define TX_TYPE_RC 2
#define TX_TYPE_USER 3
#define TxType() @(0x210010)
__nolist void SetTxType(const int &t) { Set(TxType(), t); }
#define TX_BAUD_2400 0
#define TX_BAUD_4800 1
#define TX_BAUD_9600 3
#define TxBaud() @(0x210011)
__nolist void SetTxBaud(const int &b) { Set(TxBaud(), b); }
#define TX_DIRECTION_FRONT_LEFT 0
#define TX_DIRECTION_FRONT_RIGHT 1
#define TX_DIRECTION_BACK 2
#define TX_DIRECTION_HIGH_POWER 3
#define TX_DIRECTION_PC 4
#define TxDirection() @(0x210012)
__nolist void SetTxDirection(const int &d) { Set(TxDirection(), d); }
#define TxUserPreamblePos() @(0x210013)
__nolist void SetTxUserPreamblePos(const int p) { Set(TxUserPreamblePos(), p);
}
#define TxUserPreambleLen() @(0x210014)
__nolist void SetTxUserPreambleLen(const int l) { Set(TxUserPreambleLen(), l);
}
#define TX_USER_NO_CHECKSUM 0
#define TX_USER_SUM_CHECKSUM 0x04
#define TX_USER_ZERO_SUM_CHECKSUM 0x08
#define TxUserChecksum() @(0x210015)
__nolist void SetTxUserChecksum(const int n) { Set(TxUserChecksum(), n); }
#define TX_USER_NO_BIPHASE 0
#define TX_USER_BIPHASE 1
#define TxUserBiPhase() @(0x210016)
__nolist void SetTxUserBiPhase(const int n) { Set(TxUserBiPhase(), n); }
#define MESSAGE_UNLOCK 0
#define MESSAGE_LOCK_IR 1
#define MESSAGE_LOCK_PC 2
#define MessageLock() @(0x210017)
__nolist void SetMessageLock(const int &l) { Set(MessageLock(), l); }
#define RxBufferIndex() @(0x210018)
#define MSG_RX_CHANNEL_IR 1
#define MSG_RX_CHANNEL_PC 2
#define MessageRxChannel() @(0x210019)
#define RxBufferIRId() @(0x21001a)
#define RxBufferPCId() @(0x21001b)
#define MSG_INDEX 0
#define MSG_COMMAND 1
#define MSG_HI_BYTE 2
#define MSG_LO_BYTE 3
#define COMMAND_CONTROLLER 0x40
#define RxIRMessage(n) @(0x21001c + (n)) // 4 bytes
#define RxPCMessage(n) @(0x210020 + (n)) // 4 bytes
__nolist void SendSerial(const int first, const int count) { asm { 0xc2, first,
count }; }
#define PingControl(n) @(0x330000 + (n)) // 51
#define PingData() PingControl(0)
__nolist void SetPingData(const int &d) { Set(PingData(), d); }
#define PingInterval() PingControl(1)
__nolist void SetPingInterval(const int &i) { Set(PingInterval(), i); }
#define PingID() PingControl(2)
#define BeaconControl(n) @(0x340000 + (n)) // 52
#define LinkID() BeaconControl(0)
#define RC_CHANNEL_BROADCAST 0
#define RC_CHANNEL_1 1
#define RC_CHANNEL_2 2
#define RC_CHANNEL_3 3
#define RC_CHANNEL_DISABLED 4
#define RCRxChannel() BeaconControl(1)
__nolist void SetRCRxChannel(const int c) { Set(RCRxChannel(), c); }
#define RCTxChannel() BeaconControl(2)
__nolist void SetRCTxChannel(const int c) { Set(RCTxChannel(), c); }
#define RCTXMODE_SINGLE_SHOT 0
#define RCTXMODE_CONTINUOUS 1
#define RCTxMode() BeaconControl(3)
__nolist void SetRCTxMode(const int m) { Set(RCTxMode(), m); }
#define IndirectEEProm() @(0x360000) // 54 ????
// __nolist void Find(int &v, const int f,
__nolist void StartTask(const int t) { asm { 0x71, t}; }
#define CONTROLLER_BUTTON1 0x0100
#define CONTROLLER_BUTTON2 0x0200
#define CONTROLLER_BUTTON3 0x0001
#define CONTROLLER_BUTTON4 0x0101
#define CONTROLLER_BUTTON5 0x0201
|
|
Message is in Reply To:
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|