ACI Recieve Variables and Command in one code (Control Loop)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ACI Recieve Variables and Command in one code (Control Loop)

Dongho Kang
This post was updated on .
Hello,

I'm trying to build a ACI software to recieve variables from UAV and command UAV.

What I want to build is a control loop, which receive variable first, and using them to calculate motor input, and command to UAV by direct motor input. (control loop)

I succeeded in 10 Hz rate, but I need to update variables and command faster. ( I want to command and receive in around 100 Hz. Actually this is why I trying to use High Level Processor, and ACI.)

I always falied to make loop faster caused by aciSynchronize() function's delay. there's no delay if aciSynchronize function used without command packet, but if I use it with command packet, it makes some problem.

I'm using Xbee Serial Communication.

Is there anyone, who succeed in build a such software via ACI?

I want some help.

ps. what's the highest communication rate in this situation?
Reply | Threaded
Open this post in threaded view
|

Re: ACI Recieve Variables and Command in one code (Control Loop)

Dongho Kang
Here is my code (I set ENGRATE = 100, HEARTBEAT = 50, COMRATE = 100)

int main() function

 155         aciInit();
 156         aciSetSendDataCallback(&transmit);
 157         //aciInfoPacketReceivedCallback(&versions);
 158         aciSetVarListUpdateFinishedCallback(&varListUpdateFinished);
 159         aciSetCmdListUpdateFinishedCallback(&cmdListUpdateFinished);
 160
 161         aciSetEngineRate(ENGRATE, HEARTBEAT);
 162
 163         pthread_create(&p_acithread, NULL, aciThread, NULL);
 164
 165         // get var list and command list (initializing)
 166         aciGetDeviceVariablesList();
 167         printf("Waiting for variable list...\n");
 168         while(!var_ready) usleep(1000);
 169
 170         aciGetVarPacketRateFromDevice();
 171         printf("Var Packet Rate : %d\n", aciGetVarPacketRate(2));
 172         aciGetDeviceCommandsList();
 173         printf("Waiting for command list...\n");
 174         while(!cmd_ready) usleep(1000);
 175
 176         pthread_create(&p_comthread, NULL, comThread, NULL);
 177         pthread_join( p_acithread, NULL);


aciThread

 192 void *aciThread(void *dump) {
 193         int result = 0;
 194         unsigned char data = 0;
 195         int cnt = 0;
 196
 197         while(1)
 198         {
 199                 cnt++;
 200                 result = read(fd, &data, 1);
 201
 202                 while (result>0) {
 203                         aciReceiveHandler(data);
 204                         result = read(fd, &data, 1);
 205                 }
 206
 207                 aciSynchronizeVars();
 208                 printf("rpm : %d\n",motorrpm * 64);
 209                 fflush(stdout);
 210                
 211                 aciEngine();
 212                 usleep(1000000 / ENGRATE);
 213         }      
 214         return NULL;
 215 }      


comThread - Updating Command Packet

217 void *comThread()
 218 {
 219         int flag = 0;
 220        
 221         motor1 = 0;
 222         motor2 = 0;
 223         motor3 = 0;
 224         motor4 = 0;
 225         aciUpdateCmdPacket(0);
 226        
 227         usleep(3000000);
 228         while(1)
 229         {
 230                 if(cmd_ready)
 231                 {
 232                         if(comFlag >= 0)
 233                         {
 234                                 printf("%d motor : %d\n", threadCnt, (25 + (motor * 175) / 200) *      43);  // rpm = (25 + ((motor command value) x 175) / 200 ) x 43
 235                                 fflush(stdout);
 236                                
 237                                 motor1 = motor;
 238                                 motor2 = motor;
 239                                 motor3 = motor;
 240                                 motor4 = motor;
 241                                
 242                                 aciUpdateCmdPacket(0);
 243                                 threadCnt++;
 244                                 comFlag = 0;
 245
 246                                 motor += add;
 247                                 recFlag = 1;
 248
 249                                 if(motor > MAXRPM)
 250                                         add = -1;
 251                                 else if(motor <= 0)
 252                                         add = 1;
 253
 254                         }
 255                 }
 256
 257                 usleep(1000000 / COMRATE);
 258         }
 259 }