Delay and troubles controlling PF motors with HTIRL
| Author |
Message |
|
Jampoz
Rookie
Joined: Sat Jan 09, 2010 12:25 pm Posts: 48 Location: Rome, Italy
|
 Re: Delay and troubles controlling PF motors with HTIRL
Sure, no problem! Here it is  |  |  |  | Code: #pragma config(Sensor, S2, HTIRL, sensorLowSpeed)
#include "drivers/HTIRL-driver.h" #include "PSP-Nx-lib.c"
#define Addr 0x02 #define SensorPort S1
int CommandL = 0; int CommandR = 0;
task main() { psp currState;
nI2CBytesReady[SensorPort] = 0; SensorType[SensorPort] = sensorI2CCustom9V;
while (true) { PSP_ReadButtonState(SensorPort, Addr, currState);
CommandL = currState.l_j_y * 0.07; CommandR = currState.r_j_y * 0.07;
PFcomboPwmMode(HTIRL, 0, (eCPMMotorCommand)CommandL, (eCPMMotorCommand)CommandL); wait1Msec(50); PFcomboPwmMode(HTIRL, 1, (eCPMMotorCommand)CommandR, (eCPMMotorCommand)CommandR); wait1Msec(50);
nxtDisplayTextLine(5,"CommandL: %d", (int)CommandL); nxtDisplayTextLine(6,"CommandR: %d", (int)CommandR); } }
|  |  |  |  |
As you can see, everything is in the main while loop, now the problem is almost 1 second delay happens between joypad interaction and tank reaction (display update and motor movement) I tried different ms delay (10, 50, 100 and 200) and always got the same delay problem
|
| Sat Jul 17, 2010 9:53 pm |
|
 |
|
Jampoz
Rookie
Joined: Sat Jan 09, 2010 12:25 pm Posts: 48 Location: Rome, Italy
|
 Re: Delay and troubles controlling PF motors with HTIRL
I think I should also explain the architecture of the tank It has 4 tracks and they move in couples, of course
|
| Sun Jul 18, 2010 5:03 pm |
|
 |
|
Gary Samad
Expert
Joined: Mon Mar 15, 2010 4:24 pm Posts: 124
|
 Re: Delay and troubles controlling PF motors with HTIRL
Can you try displaying the number of loops, in order to understand whether the main loop is still looping 10 times for each 1 second delay, or whether the main loop is only executing one time per second? cu, Gary
|
| Sun Jul 18, 2010 5:07 pm |
|
 |
|
Jampoz
Rookie
Joined: Sat Jan 09, 2010 12:25 pm Posts: 48 Location: Rome, Italy
|
 Re: Delay and troubles controlling PF motors with HTIRL
I guess it does execute once per second as the display doesn't update If I remove the motor command I get realtime update on the display
But I'm making a counter and going to display it this evening, thanx for the useful suggestion!
|
| Mon Jul 19, 2010 5:15 am |
|
 |
|
Jampoz
Rookie
Joined: Sat Jan 09, 2010 12:25 pm Posts: 48 Location: Rome, Italy
|
 Re: Delay and troubles controlling PF motors with HTIRL
Guess Xander's hint on the other thread nailed something, here is the new version I'm working on I didn't have time to make it "elegant" so please deal with it, good thing is I actually added some comments   |  |  |  | Code: #pragma config(Sensor, S2, HTIRL, sensorLowSpeed)
#include "drivers/HTIRL-driver.h" #include "PSP-Nx-lib.c"
#define Addr 0x02 #define SensorPort S1
// Store Motor commands into an Array int Commands[2];
task main() { psp currState; nI2CBytesReady[SensorPort] = 0; SensorType[SensorPort] = sensorI2CCustom9V; while (true) { PSP_ReadButtonState(SensorPort, Addr, currState); // Fill Array with Joypad input Commands[0] = currState.l_j_y * -0.07; Commands[1] = currState.r_j_y * 0.07; // Elaborate Joypad input and control both Motors for ( int cmd = 0; cmd < 2; cmd++ ) { if( Commands[cmd] == 0 ) { // IF No input PFcomboPwmMode(HTIRL, cmd, CPM_MOTOR_BRAKE, CPM_MOTOR_BRAKE); } else if( Commands[cmd] < 0 ) { // IF FORWARD Commands[cmd] = Commands[cmd] * -1; PFcomboPwmMode(HTIRL, cmd, (eCPMMotorCommand)Commands[cmd], (eCPMMotorCommand)Commands[cmd]); } else if( Commands[cmd] > 0 ) { // IF BACK Commands[cmd] = 16 - Commands[cmd]; PFcomboPwmMode(HTIRL, cmd, (eCPMMotorCommand)Commands[cmd], (eCPMMotorCommand)Commands[cmd]); } } // Display Joypad input nxtDisplayTextLine(5,"CommandL: %d", (int)Commands[0]); nxtDisplayTextLine(6,"CommandR: %d", (int)Commands[1]); } }
|  |  |  |  |
Now delay seems really shorter, yet it's present, but the tank is driveable at least! Need to dig deeper because the Task way, even if wrong and controlling one Motor only, gave me an outstanding real-time control By the way, thank you all once again for the help
|
| Thu Jul 22, 2010 8:55 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
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
|
|