|
Page 1 of 1
|
[ 5 posts ] |
|
cross platform compatability
Author |
Message |
fretless_kb
Rookie
Joined: Wed Feb 09, 2011 1:08 am Posts: 27
|
 cross platform compatability
I finally got the boot-loader for Robot C onto my Arduino Mega, and this looks really cool. But I still struggle with cross platform comparability between the Cortex and the Mega, specifically the command abort time slice vs end time slice. They appear to have the same functionality, but end time slice is not supported under the Arduino platform. is end time slice going to be deprecated from the Cortex support?
Cheers Kb
|
Fri Dec 07, 2012 9:57 am |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: cross platform compatability
You are absolutely correct, the abortTimeSlice() and endTimeSlice() commands work exactly the same: We are looking to deprecate (but not remove) one or the other from ROBOTC moving forward, but are not sure which one will remain active. In the meantime, you can do a simple find and replace in any code that has the EndTimeSlice(); command and replace it with abortTimeSlice();
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|
Fri Dec 07, 2012 1:13 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: cross platform compatability
Or simply add the following define. I don't have RobotC in front of me so I can't search for the Arduino Platform defines.
|
Fri Dec 07, 2012 3:03 pm |
|
 |
fretless_kb
Rookie
Joined: Wed Feb 09, 2011 1:08 am Posts: 27
|
 Re: cross platform compatability
Thanks for the quick reply, now I have another issue. I trying to get my multi robot code to work I found code I wrote for the Cortex Seems to run fun, when I ported it to the Arduino I am not getting the same result at all. I have a main piece of code here:  |  |  |  | Code: #pragma config(CircuitBoardType, typeCktBoard2560) #pragma config(Sensor, dgtl3, red, sensorDigitalOut) #pragma config(Sensor, dgtl8, yellow, sensorDigitalOut) #pragma config(Sensor, dgtl9, green, sensorDigitalOut) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "SerialInterfaceCode_maxSpeedCortex.h"; // // uses strings to send and receive data (Sep 2012) // added binary mode & method to switch (Oct 2012) //
#define STRING_PAUSE 60 // 60 // int RxDelay = 2; task main() {
initSerialPort (); VexDataInit( myVexDataRx ); VexDataInit( myVexDataTx ); writeDebugStreamLine("Starting...");
StartTask(serialRxTask); StartTask(sendVexData); #ifdef FINEPRINT writeDebugStreamLine("FINEPRINT on"); #endif
while (true) { // begin main program loop // wait10Msec(RxDelay);
}// end main program loop
} // end task main
|  |  |  |  |
and a library of functions along with a data structure here:  |  |  |  | Code: /* Post XBee I/F Troubleshooting This Library demonstrates Serial Communicastions Ascii or Binary Transmission sets up a sample framework for datatransfer frames with chesksums For Vex Robotics Cortex Alternative Serial Communications */ // Storage for the vex communications data #define VEXDATAOFFSET 5 #define VEX_DATA_BUFFER_SIZE 44 #define MESSAGE_LENGTH 19 #define INPUT_STRING_SIZE 19
//#define TX_STEP 1500 // ms pause between transmissions //#define RX_PAUSE 14 // 10 60 This is the RX loop pause int RX_PAUSE = 1; int TX_STEP=1250; int remoteWheelLeft=0,remoteWheelRight=0; // //#define FINEPRINT 1 #define FINE_PRINT_TX 1 #define DEBUG 1
void VexDataChecksumTx(void);
long time = 0; int hours,minutes,seconds; //long myLeftOSE=0,myRightOSE=0; bool TxFlag=true;
#ifdef FINEPRINT long millisec = 0; #endif
static long timeout =0;
struct { // <40 Bytes unsigned char header_56; unsigned char header_A5; unsigned char deviceId; unsigned char messageId; unsigned char messageLength; //5 bytes unsigned char hours; unsigned char minutes; unsigned char seconds; unsigned char milli_secH; unsigned char milli_secL; unsigned char WheelL_H; unsigned char WheelL_L; unsigned char WheelR_H; unsigned char WheelR_L; unsigned char MotorL; unsigned char MotorR; unsigned char Spare_H; unsigned char Spare_L; unsigned char checksum; //19 bytes } datas;
union { datas data; unsigned char buffer[VEX_DATA_BUFFER_SIZE]; } vexdata;
vexdata myVexDataRx,myVexDataTx;
// Functions void SendString(string sOutgoing) // should convert this to a task as well { while(strlen(sOutgoing)) { sendChar(UART2, StringGetChar(sOutgoing, 0)); StringDelete(sOutgoing, 0, 1); wait1Msec(1); while(!bXmitComplete(UART2)) {abortTimeslice();} } } //
void timeTag() { int temp=0; time = time1[T1]; temp = floor(time/1000.0); // Format Time into HH:MM:SS minutes = floor(temp/60.0); hours = floor(minutes/60.0); seconds = floor(temp - (minutes*60) - (hours*3600)); return; }
void initSerialPort () { // initialize the serial port configureSerialPort(UART2, uartUserControl); setBaudRate(UART2, baudRate115200); return; }
// tasks task sendVexData() {
long timeCheck=0,timeCheckOld=0;
while (true) { timeCheck = time1[T1]; // translate timetag timeTag(); // Send Data every time step // Send data in Binary if ((timeCheck >= timeCheckOld + TX_STEP)&&(TxFlag)){ // Timestamp myVexDataTx.data.hours = hours; myVexDataTx.data.minutes = minutes; myVexDataTx.data.seconds = seconds; myVexDataTx.data.MotorL = 20; myVexDataTx.data.MotorR = 20; //
VexDataChecksumTx( );
for (int i=0; i < MESSAGE_LENGTH; i++) {
#ifdef FINE_PRINT_TX long millisec =0; millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStreamLine("Tx %d",myVexDataTx.buffer[i]); #endif sendChar(UART2, myVexDataTx.buffer[i]); wait1Msec(1); while(!bXmitComplete(UART2)) {abortTimeslice();} }
#ifdef FINE_PRINT_TX writeDebugStream("\n%d:%d:%d ",myVexDataTx.data.hours,myVexDataTx.data.minutes,myVexDataTx.data.seconds); writeDebugStream(" Tx good data %X\n",myVexDataTx.data.checksum); #endif timeCheckOld = timeCheck; } // end timestep Xmit } // end while } // end task TxVexData // /*-----------------------------------------------------------------------------*/ /* */ /* Timeout code */ /* */ /*-----------------------------------------------------------------------------*/
void StartTimeout( ) { // Start timeout timeout = time1[T1]; }
void StopTimeout( ) { // Stop timeout timeout = 0; }
int CheckTimeout( ) { // Is timeout running ? if( timeout > 0 ) { if((time1[T1] - timeout) < 20) return(0); else return(1); } return(0); }
void VexDataChecksumTx( ) { int i; int cs = 0;
for(i=VEXDATAOFFSET;i<abs(myVexDataTx.data.messageLength-1);i++) cs = cs ^ myVexDataTx.buffer[i]; myVexDataTx.data.checksum = (cs & 0xFF); return; }
void VexDataChecksumRx( ) { int i; int cs = 0;
for(i=VEXDATAOFFSET;i<abs(myVexDataRx.data.messageLength-1);i++) //myVexDataRx.data.messageLength);i++) cs = cs ^ myVexDataRx.buffer[i]; myVexDataRx.data.checksum = (cs & 0xFF); return; }
void VexDataInit( vexdata &v ) { int i;
// clear all for(i=0;i<VEX_DATA_BUFFER_SIZE;i++) v.buffer[i] = 0; // Initialize packet v.data.header_56 = 0x56; v.data.header_A5 = 0xA5; v.data.deviceId = 0x02; v.data.messageId = 0x02; v.data.messageLength= MESSAGE_LENGTH; //writeDebugStreamLine("init rx/tx length : %d",v.data.messageLength); }
//task serialRxTask() task serialRxTask() { static int serialRxState=0; static int serialDataReceived = 0; short c;
while (true) { // check for a received character c = getChar(UART2); if( c < 0 ) { // no received char // Check for inter char timeout if( CheckTimeout() == 1 ){ serialRxState = 0; StopTimeout(); writeDebugStream("timeout %d \n",timeout); } //wait1Msec(1); } // A new character has been received so process it.
// Start inter char timeout StartTimeout();
// Where are we in the message parsing process ? switch( serialRxState ) { case 0: // look for first header byte if( (unsigned char)c == myVexDataRx.data.header_56 ) { #ifdef FINEPRINT millisec = time1[T1]; writeDebugStream("\n%d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStream("%1X",c); #endif serialRxState++; } else StopTimeout();
break;
case 1: // look for second header byte if( (unsigned char)c == myVexDataRx.data.header_A5 ) {
#ifdef FINEPRINT millisec = time1[T1]; writeDebugStream("\n%d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStream("%1X",c); #endif serialRxState++; } else { // Bad message StopTimeout(); serialRxState = 0; writeDebugStreamLine("bombed"); } break;
case 2: // We have a good header so next is device ID High byte myVexDataRx.data.deviceId = c;
#ifdef FINEPRINT millisec = time1[T1]; writeDebugStream("%d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStreamLine("%1X",c); #endif serialRxState++; break;
case 3: // message ID myVexDataRx.data.messageId=c;
#ifdef FINEPRINT millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStreamLine("%1X",c); #endif serialRxState++; break;
case 4: // next is message length (expect 11 or 0x0B) myVexDataRx.data.messageLength=c; if (myVexDataRx.data.messageLength > 11) { myVexDataRx.data.messageLength = 11; } // limit check message length #ifdef FINEPRINT millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStreamLine("%1X",c); #endif serialRxState++; serialDataReceived =8; break;
case 5: // receive the data packet myVexDataRx.buffer[serialDataReceived ] = c; #ifdef FINEPRINT millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStreamLine("%1X",c); #endif if( ++serialDataReceived == MESSAGE_LENGTH-1){ // myVexDataRx.data.messageLength ){ serialRxState++; } // check for buffer overflow - This check worked but the checksum failed // with buffer overflow when getting bad length data in if( serialDataReceived > (MESSAGE_LENGTH) ) { // Error StopTimeout(); serialRxState = 0; writeDebugStream("overflow data\n"); } break;
case 6: // Received checksum byte #ifdef FINEPRINT millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStream("RxState is %d ",serialRxState); writeDebugStreamLine("%1X",c); #endif // stop timeout StopTimeout();
// calculate received checksum VexDataChecksumRx( ); // comapare checksums #ifdef FINEPRINT millisec = time1[T1]; writeDebugStream(" %d ms ",millisec); writeDebugStream("Calcd checksum is ",serialRxState); writeDebugStreamLine("%1X",myVexDataRx.data.checksum); #endif
if( (unsigned char)c == myVexDataRx.data.checksum) { // Good data #ifdef DEBUG remoteWheelLeft = myVexDataRx.data.WheelL_H << 8; remoteWheelLeft = myVexDataRx.data.WheelL_H & 0xFF00; remoteWheelLeft = remoteWheelLeft + myVexDataRx.data.WheelL_L; remoteWheelRight = myVexDataRx.data.WheelR_H << 8; remoteWheelRight = myVexDataRx.data.WheelR_H & 0xFF00; remoteWheelRight = remoteWheelRight + myVexDataRx.data.WheelR_L; writeDebugStream("\n%d:%d:%d ",myVexDataRx.data.hours,myVexDataRx.data.minutes,myVexDataRx.data.seconds); writeDebugStream(" PotValue = %d ",remoteWheelLeft); #endif writeDebugStream(" good data\n"); } else { writeDebugStream(" bad data\n");
}
// done serialRxState = 0; //wait1Msec(CHAR_PAUSE); break;
default: } // end case wait1Msec(RX_PAUSE); } // end while } // end task
|  |  |  |  |
When I run this code one the cortex (the only difference is the first pragma line) and examine the Debug Stream I can see the data which is to be sent to the serial port and it updates as I would expect, but when I use the same code on the Arduino I don't get the same effect. I get data that doesn't change including the time tag. Here's the output of the Cortex Run. 0:0:3 Tx good data 3 5001 ms Tx 86 5002 ms Tx 165 5003 ms Tx 2 5004 ms Tx 2 5005 ms Tx 19 5006 ms Tx 0 5007 ms Tx 0 5008 ms Tx 5 5009 ms Tx 0 5010 ms Tx 0 5011 ms Tx 0 5012 ms Tx 0 5013 ms Tx 0 5014 ms Tx 0 5015 ms Tx 20 5016 ms Tx 20 And here is the output from the same code on the Arduino. 235:0:3369 Tx good data EB 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123 9766 ms Tx 123
Any Ideas on how to port this type of code successfully? I am thinking at this point it has something to do with the data structure in use. Cheers Kb
|
Sat Dec 08, 2012 9:57 pm |
|
 |
fretless_kb
Rookie
Joined: Wed Feb 09, 2011 1:08 am Posts: 27
|
 Re: cross platform compatability
Well coding for just a buffer vs a union had no effect, the code in either case works with the Cortex platform but not the arduino, so something else is going on. Any help would be appreciated. Thanks - Kb
|
Mon Dec 10, 2012 9:57 am |
|
|
|
Page 1 of 1
|
[ 5 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|