Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   IR Issues in Mplab (http://www.chiefdelphi.com/forums/showthread.php?t=61989)

drewjones13 18-01-2008 18:25

IR Issues in Mplab
 
We are currently using mplab and we having trouble with the pulses of the remote. Here is an example of our coding:
Code
Code:

if (rc_dig_in10 == 1)
{
    cmd0; //Call the cmd0(forward) subroutine
}

Subroutine
Code:

unsigned char cmd0()
{
    pwm01 = pwm02 = 190; //Forward Half Speed
    return 0;
}

Basically this is saying that if rc_dig_in10(we are using digital i/o ports 10 through 13) is equal to 1 it will call the cmd0 subroutine. The cmd0 subroutine tells both wheels to go forward half speed.
But this makes it so the pulses just pulse the motors forward and do not hold them at constant forward movement. What are other teams doing to rectify/compensate for this?

usbcd36 18-01-2008 18:40

Re: IR Issues in Mplab
 
There doesn't seem to be anything wrong with the code you posted; the error may lie elsewhere.

In the autonomous loop, are you setting the PWMs to 127 every time?

Laaba 80 18-01-2008 19:04

Re: IR Issues in Mplab
 
Quote:

Originally Posted by drewjones13 (Post 681043)
if (rc_dig_in10 == 1)
{
cmd0; //Call the cmd0(forward) subroutine
}
[/code]
Subroutine
Code:

unsigned char cmd0()
{
    pwm01 = pwm02 = 190; //Forward Half Speed
    return 0;
}


What I think your problem is that you have nothing telling it how far to go. You may also not want to directly call the subroutine from the sensor do something to the sort of.

if (rc_dig_in10 == 1)
{
ButtonPressed = TRUE;
}
[/code]
Subroutine[code]
if (ButtonPressed == TRUE)
{
//You could also call your subroutine here if you wanted to
pwm01 = pwm02 = 190; //Forward Half Speed
return 0;
}

This will work because the way you had it written, as soon as the button lets go, it equals 0. Since the processor runs every 27 milliseconds or so, it will start, and then quickly stop if pressed once. Doing it the way I showed sets another variable that once it sees the button gets set, and if it gets let go it is still going. If you have anymore questions, let me know.
Joey


PS I'm not sure if the syntax is perfect, I just wanted to show you the concept.

drewjones13 18-01-2008 19:36

Re: IR Issues in Mplab
 
We were able to figure it out. The issue was with an else branch that we had that was setting the pwm01 and pwm02 equal to 127.


All times are GMT -5. The time now is 04:57.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi