ROBOTC.net forums
http://robotc.net/forums/

problem with my program
http://robotc.net/forums/viewtopic.php?f=11&t=1711
Page 1 of 1

Author:  indica3d [ Sat May 30, 2009 5:24 am ]
Post subject:  problem with my program

HI to all.

i am new to robotc and new to c programming.
i try to write a program that move my robot just with ch1+ch2 on the remote.
the only part of the program that work is (ch2-up + ch1 left)
anyone know what am i doing rong?

here is my code :

/* conguration:

left motor= port2
right motor= port3
*/

task main ()
{
bMotorReflected[port2] = 1; // change motor 2 diraction because motore 2 is reverse side
bVexAutonomousMode = false; //Activates Remote Control Mode

while (1==1)
{
if (vexRT[Ch1] == 0 && vexRT[Ch2]>0) // if just channel 2 is active up > move forward
{
motor[port2]= vexRT[Ch2];
motor[port3]= vexRT[Ch2];
}
if (vexRT[Ch1] == 0 && vexRT[Ch2]<0 ) // if just channel 2 is active down > move backward
{
motor[port2]= vexRT[Ch2];
motor[port3]= vexRT[Ch2];
}
if (vexRT[Ch2]==0 && vexRT[Ch1] > 0 ) //if just channel 1 is active to right > move right in place
{
motor[port2]= vexRT[Ch1];
motor[port3]= - vexRT[Ch2];
}
if (vexRT[Ch2]==0 && vexRT[Ch1] < 0 ) // if just channel 1 is active to left > move left in place
{
motor[port2]= vexRT[Ch1];
motor[port3]= - vexRT[Ch2];
}
if (vexRT[Ch2]>0 && vexRT[Ch1] > 0 ) //if chanel 2 up and channel 1 right
{
motor[port2]= (vexRT[Ch2])-((vexRT[Ch2]* vexRT[Ch1])/127);
motor[port3]= vexRT[Ch2];
{
if (vexRT[Ch2]>0 && vexRT[Ch1] < 0 ) //if channel 2 up and channel 1 left
{
motor[port2]= vexRT[Ch2];
motor[port3]= (vexRT[Ch2])+((vexRT[Ch2]* vexRT[Ch1])/127);
}
if (vexRT[Ch2]<0 && vexRT[Ch1] > 0) //if channel 2 down and channel 1 right
{
motor[port2]= vexRT[Ch2];
motor[port3]= (vexRT[Ch2])-((vexRT[Ch2]* vexRT[Ch1])/127);
}
if (vexRT[Ch2]<0 && vexRT[Ch1] < 0) //if channel 2 down and channel 1 left
{
motor[port2]= (vexRT[Ch2])+((vexRT[Ch2]* vexRT[Ch1])/127);
motor[port3]= vexRT[Ch2];
}
else
{
motor[port2]= 0;
motor[port3]= 0;
}
}
}
}



Thanks for the help
asher
}

Author:  mightor [ Sat May 30, 2009 8:11 am ]
Post subject:  Re: problem with my program

Moved to correct forum.

Author:  jbflot [ Tue Jun 02, 2009 5:06 pm ]
Post subject:  Re: problem with my program

Try this code out, a slightly modified version from the "Single Joystick Control" Sample program:

Code:
task main()
{
   bMotorFlippedMode[port2] = 1;    //Port 2 Motor Direction Flipped
   bVexAutonomousMode = false;         //Activates Remote Control Mode

   while (true)   //Creates an infinite loop
   {
      motor[port2] = vexRT[Ch2]/2 - vexRT[Ch1]/2;      //y-axis value: forward/backward motion
      motor[port3] = vexRT[Ch2]/2 + vexRT[Ch1]/2;      //x-axis value: left/right steering
                                                                           //divided by 2 to prevent values over 127
   }
}

Author:  fryfrog [ Thu Jun 04, 2009 8:17 pm ]
Post subject:  Re: problem with my program

And if you remove the "/2" you won't limit your top speed artificially. That is the code I

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/