View unanswered posts | View active topics It is currently Wed Aug 27, 2014 5:20 am






Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Delay and troubles controlling PF motors with HTIRL 
Author Message
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Delay and troubles controlling PF motors with HTIRL
Here I am again

Let's go straight to some code posting and then explain the problem, I'll go thru this loop twice with two different code versions and, of course, two different problems :D

(I spared a conversion code to keep things short, the CommandL/R will only give 1-6 as useful commands)

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);
      PFcomboPwmMode(HTIRL, 1, (eCPMMotorCommand)CommandR, (eCPMMotorCommand)CommandR);
      
      nxtDisplayTextLine(5,"CommandL: %d", (int)CommandL);
      nxtDisplayTextLine(6,"CommandR: %d", (int)CommandR);
   }
}


This way, I get the motors to move fine, but I also get about 1sec delay between interacting with the joypad and the actual motor action, it's weird it takes so much time to do the stuff so I thought about tasks and tried this other wersion...

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 Motore() {
   PFcomboPwmMode(HTIRL, 0, (eCPMMotorCommand)CommandL, (eCPMMotorCommand)CommandL);
   PFcomboPwmMode(HTIRL, 1, (eCPMMotorCommand)CommandR, (eCPMMotorCommand)CommandR);
}

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;

      StartTask(Motore, 10);
      
      nxtDisplayTextLine(5,"CommandL: %d", (int)CommandL);
      nxtDisplayTextLine(6,"CommandR: %d", (int)CommandR);
   }
}


Now the motor move perfectly, but I didn't use plural form as it does execute only the first command, moving the motor on port 0 and not the motor on port 1

I tried using 2 tasks for the 2 motors but it seems stupid as the number of tasks is limited, and even then, RobotC complained about using the function PFcomboPwmMode twice in parallel on two different tasks and the same time

There must be some solution and I feel like I'm close to it, yet so far away that I'm forced to ask here for help

Thank you all if you feel like trying to give me something to work on!


Sat Jul 10, 2010 7:11 pm
Profile
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post Re: Delay and troubles controlling PF motors with HTIRL
Looks to me like you don't really need a motors "task", but just a function. Try defining:

task Motore()

as

void Motore()

and calling it directly using

Motore();

cu,
Gary


Sat Jul 10, 2010 8:04 pm
Profile
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
Thank you Gary but using a function makes the motors answer with almost 1sec delay just like the first example having the commands inside the main task :(


Sat Jul 10, 2010 11:23 pm
Profile
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post Re: Delay and troubles controlling PF motors with HTIRL
Another thing to try is to add a wait1Msec(10) or similar in your loop, so that will free up the CPU to do other work.

cu,
Gary


Sun Jul 11, 2010 5:41 pm
Profile
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
To add a Pause in order to fix a Delay, that's wicked!
Now I'm at office but I'll try this one as soon as I reach home, can't wait to fix that in order to code other features

Thank you!


Mon Jul 12, 2010 4:18 am
Profile
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
I still have to try the ms pause hint, need some spare time, hopefully I'll do it this evening

Any word from Xander about the issue, by the way? :D


Wed Jul 14, 2010 7:46 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Delay and troubles controlling PF motors with HTIRL
What issue? I thought the problem was resolved by changing the tasks to a function?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jul 14, 2010 9:16 am
Profile WWW
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
Nope, function still gives a 1 sec delay
I'm gonna try to wait 10 ms this evening

But why does the task move only one motor? why does it ignore the second command?


Wed Jul 14, 2010 10:49 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Delay and troubles controlling PF motors with HTIRL
Just attach your current program (don't paste it). I'll take a look. I can't test anything as I am on vacation and don't have my NXTs with me.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jul 14, 2010 11:28 am
Profile WWW
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
Man I'd bring my NXT on vacation... it sucks I can't take it at the office :D
Will send you the code later when I get home, after I test the last hints I received

Thank you, hope the best for you on your vacation ;)


Wed Jul 14, 2010 11:34 am
Profile
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
Alright, this is the version I'm trying right now, all problems remain even with the pauses

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 Motore()
{
   PFcomboPwmMode(HTIRL, 0, (eCPMMotorCommand)CommandL, (eCPMMotorCommand)CommandL);
   wait1Msec(200);
   PFcomboPwmMode(HTIRL, 1, (eCPMMotorCommand)CommandR, (eCPMMotorCommand)CommandR);
   wait1Msec(200);
}

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;

      StartTask(Motore, 10);

      nxtDisplayTextLine(5,"CommandL: %d", (int)CommandL);
      nxtDisplayTextLine(6,"CommandR: %d", (int)CommandR);
   }
}


If I place the 2 PFcomboPwmMode inside the main while loop, I get 1sec delay between the joypad interaction and the actual motor reaction

If I use the Motore task technique I get a super fast motor response but it only execute the first PFcomboPwmMode, moving one track only

Using delay doesn't help, I tried from 10 to 200ms delay

What am I doing wrong?


Sat Jul 17, 2010 9:54 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Delay and troubles controlling PF motors with HTIRL
You shouldn't use tasks like that. Just turn it into a normal function.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Jul 17, 2010 12:38 pm
Profile WWW
Rookie

Joined: Sat Jan 09, 2010 12:25 pm
Posts: 48
Location: Rome, Italy
Post Re: Delay and troubles controlling PF motors with HTIRL
Using a function still gives me the delay problem
I interact with the joypad and I can see display update and motor motion after like 1 second, it's unusable like that

Why do I get a delay when controlling two motors and I get none using a task? And why do the task run only 1 PFcomboPwmMode instead of 2?
I can't understand


Sat Jul 17, 2010 12:51 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Delay and troubles controlling PF motors with HTIRL
I can't really look at this code until the end of next week as I am on vacation.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Jul 17, 2010 1:34 pm
Profile WWW
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post Re: Delay and troubles controlling PF motors with HTIRL
Jampoz, it looks to me that you need to do both - not use a task (this isn't the right way to use it, just use a function or put the two lines of code back into the main loop), and you need the wait in the loop. Without both of these changes, I don't think you can make further progress. After these two changes, if there are still problems, please post your code and describe the behavior.

cu,
Gary


Sat Jul 17, 2010 6:08 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page 1, 2  Next

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

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.