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

Dual FTC Controller Coding
http://robotc.net/forums/viewtopic.php?f=52&t=10496
Page 1 of 1

Author:  terry.nelson [ Sat Feb 07, 2015 12:08 am ]
Post subject:  Dual FTC Controller Coding

Please explain how to write RobotC code to use 2 controllers during competition.

We want to have both controllers to be clones.

We have a functional teleop program but we can only use one controller.

Please help a very rookie team.

Thanks
TLN

Author:  terry.nelson [ Sat Feb 07, 2015 4:18 pm ]
Post subject:  Re: Dual FTC Controller Coding

Here is the basic code i've been working with:
I also attached the actual file



#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//


#include "JoystickDriver.c"

task main()
{
int threshold = 7; /* Int 'threshold' will allow us to ignore low */
/* readings that keep our robot in perpetual motion. */

while(true) // Infinite loop:
{
getJoystickSettings(joystick);

if(joystick.joy1_y1 < 7 && joystick.joy1_y1 > -7 && joystick.joy1_y2 < 7 && joystick.joy1_y2 > -7) //DEAD ZONE
{
motor[motorD] = 0; // ALL STOP
motor[motorE] = 0; // ALL STOP
}

if(abs(joystick.joy1_y2) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorD] = joystick.joy1_y2; // Motor D is assigned a power level equal to the right analog stick's Y-axis reading.
}
if(abs(joystick.joy1_y1) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorE] = joystick.joy1_y1; // Motor E is assigned a power level equal to the left analog stick's Y-axis reading.
}
}


//CONTROLLER #2

while(1==1) // Infinite loop:
{
getJoystickSettings(joystick);

if(joystick.joy2_y2 < 7 && joystick.joy2_y2 > -7 && joystick.joy2_y1 < 7 && joystick.joy2_y1 > -7)
{
motor[motorD] = 0; // ALL STOP
motor[motorE] = 0; // ALL STOP
}

if(abs(joystick.joy2_y2) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorD] = joystick.joy2_y2; // Motor D is assigned a power level equal to the right analog stick's Y-axis reading.
}

if(abs(joystick.joy2_y1) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorE] = joystick.joy2_y1; // Motor E is assigned a power level equal to the left analog stick's Y-axis reading.
}


}

}

Attachments:
NEED HELP.c [2.34 KiB]
Downloaded 812 times

Author:  Cyks [ Sat Feb 07, 2015 11:07 pm ]
Post subject:  Re: Dual FTC Controller Coding

From what I see if I am understanding this right, you guys have two infinite loops: while (true), and while (1==1) after the first one.

When you run this program the program "flow" will get stuck in this first one (while (true)) and it wont ever get to the second loop. So you wanna put both controls into the same loop. :)

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