<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="https://stemrobotics.org/mediawiki/skins/common/feed.css?164"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Twitch Software - Revision history</title>
		<link>https://stemrobotics.org/mediawiki/index.php?title=Twitch_Software&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.13.2</generator>
		<lastBuildDate>Fri, 29 May 2026 20:01:49 GMT</lastBuildDate>
		<item>
			<title>Foster: New page: The Twitch software was written for the VEX controller.  It uses a combination of MPLabs C and the WPILibrary.    &lt;source lang=&quot;c&quot;&gt;  #define _VEX_BOARD #include &quot;API.h&quot; #include &quot;BuiltIns....</title>
			<link>https://stemrobotics.org/mediawiki/index.php?title=Twitch_Software&amp;diff=199&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: The Twitch software was written for the VEX controller.  It uses a combination of MPLabs C and the WPILibrary.    &amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;  #define _VEX_BOARD #include &amp;quot;API.h&amp;quot; #include &amp;quot;BuiltIns....&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The Twitch software was written for the VEX controller.  It uses a combination of MPLabs C and the WPILibrary.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define _VEX_BOARD&lt;br /&gt;
#include &amp;quot;API.h&amp;quot;&lt;br /&gt;
#include &amp;quot;BuiltIns.h&amp;quot;&lt;br /&gt;
/*&lt;br /&gt;
Twich Robot Wheel and Orientation&lt;br /&gt;
&lt;br /&gt;
   1 -- N -- 2 &lt;br /&gt;
   |         |&lt;br /&gt;
   W         E&lt;br /&gt;
   |         |&lt;br /&gt;
   3 -- S -- 4&lt;br /&gt;
&lt;br /&gt;
From the drawing, when North is the front, then the right wheels are 2,4.  &lt;br /&gt;
When West is the front, then the right wheels are 1,2.  &lt;br /&gt;
&lt;br /&gt;
When we built the robot we had colored tape (red, yellow, green, white) &lt;br /&gt;
on the bumpers and corresponding tape on the joystick.  &lt;br /&gt;
&lt;br /&gt;
The driver taps the joystick to the color they want to be front, if needed &lt;br /&gt;
the robot &amp;quot;twitches&amp;quot; and the direction of the front moves. &lt;br /&gt;
&lt;br /&gt;
Team 1640 -- Foster Schucker -- July 2008 -- Initial version&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
#define MOTOR_1 1&lt;br /&gt;
#define MOTOR_2 2&lt;br /&gt;
#define MOTOR_3 3&lt;br /&gt;
#define MOTOR_4 4&lt;br /&gt;
&lt;br /&gt;
#define TWITCH_MOTOR_1 6&lt;br /&gt;
#define TWITCH_MOTOR_2 7&lt;br /&gt;
#define LIMIT_RELEASED  1   &lt;br /&gt;
#define LIMIT_PRESSED   0  &lt;br /&gt;
#define FRONT_LIMIT 11  &lt;br /&gt;
#define BACK_LIMIT  10  &lt;br /&gt;
unsigned char front_limit_val, back_limit_val;&lt;br /&gt;
&lt;br /&gt;
unsigned char twitch_state;&lt;br /&gt;
#define NORTHSOUTH 1 &lt;br /&gt;
#define EASTWEST 2&lt;br /&gt;
#define N_TRIGGER 60 &lt;br /&gt;
// needs to be 0 - 127&lt;br /&gt;
#define E_TRIGGER 200&lt;br /&gt;
// needs to be 127 - 255&lt;br /&gt;
#define S_TRIGGER 200&lt;br /&gt;
// needs to be 127 - 255&lt;br /&gt;
#define W_TRIGGER 60&lt;br /&gt;
// needs to be 0 - 127&lt;br /&gt;
&lt;br /&gt;
unsigned char front;&lt;br /&gt;
#define NORTH 1&lt;br /&gt;
#define EAST 2&lt;br /&gt;
#define SOUTH 3&lt;br /&gt;
#define WEST 4&lt;br /&gt;
&lt;br /&gt;
unsigned char t_ns,t_ew;  // We put the values in here from the transmitter&lt;br /&gt;
&lt;br /&gt;
unsigned char m_right, m_left, m_twitch;&lt;br /&gt;
&lt;br /&gt;
void IO_Initialization(void) &lt;br /&gt;
{&lt;br /&gt;
	PrintToScreen(&amp;quot;IO_Initialization\n\r&amp;quot;);&lt;br /&gt;
	SetCompetitionMode(0,1100);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Initialize(void) // When the robot is turned on this gets done first &lt;br /&gt;
{&lt;br /&gt;
	PrintToScreen(&amp;quot;Twitch 1.0 - Team 1640\n\r&amp;quot;);&lt;br /&gt;
} // End of Initialize code&lt;br /&gt;
&lt;br /&gt;
void Autonomous(void) // Autonomous code&lt;br /&gt;
{&lt;br /&gt;
		PrintToScreen(&amp;quot;Auton\n\r&amp;quot;);&lt;br /&gt;
} // End of Autonomous code&lt;br /&gt;
&lt;br /&gt;
void OperatorControl(void) // Driver control code&lt;br /&gt;
{ &lt;br /&gt;
	PrintToScreen(&amp;quot;OperatorControl\n\r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
} // End of Driver code &lt;br /&gt;
&lt;br /&gt;
void StopMotor(void)&lt;br /&gt;
{&lt;br /&gt;
	// stops all the motors while we twitch&lt;br /&gt;
	SetPWM(MOTOR_1,127);&lt;br /&gt;
	SetPWM(MOTOR_2,127);&lt;br /&gt;
	SetPWM(MOTOR_3,127);&lt;br /&gt;
	SetPWM(MOTOR_4,127);&lt;br /&gt;
} // End of StopMotor&lt;br /&gt;
&lt;br /&gt;
void CheckTwitch(void) // Check the twitch positions and if needed change state&lt;br /&gt;
{&lt;br /&gt;
	t_ns = GetRxInput(1,3);&lt;br /&gt;
	t_ew = GetRxInput(1,4);&lt;br /&gt;
&lt;br /&gt;
	// PrintToScreen(&amp;quot;NS = %d, EW= %d &amp;quot;,(int)t_ns, (int)t_ew);&lt;br /&gt;
	if (t_ns &amp;lt; N_TRIGGER)&lt;br /&gt;
	{&lt;br /&gt;
		front = NORTH;&lt;br /&gt;
		twitch_state = NORTHSOUTH;&lt;br /&gt;
	} else if (t_ew &amp;gt; E_TRIGGER)&lt;br /&gt;
	{&lt;br /&gt;
		front = EAST;&lt;br /&gt;
		twitch_state = EASTWEST;&lt;br /&gt;
	}else if (t_ns &amp;gt; S_TRIGGER)&lt;br /&gt;
	{&lt;br /&gt;
		front = SOUTH;&lt;br /&gt;
		twitch_state = NORTHSOUTH;&lt;br /&gt;
	} else if (t_ew &amp;lt; W_TRIGGER)&lt;br /&gt;
	{&lt;br /&gt;
		front = WEST;&lt;br /&gt;
		twitch_state = EASTWEST;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	front_limit_val = GetDigitalInput ( FRONT_LIMIT ) ; &lt;br /&gt;
               // Recieves input for the front limit switch&lt;br /&gt;
        back_limit_val = GetDigitalInput ( BACK_LIMIT ) ; &lt;br /&gt;
              // Recieves input for the back limit switch&lt;br /&gt;
	&lt;br /&gt;
        // Work out if we need to twitch and then move&lt;br /&gt;
	if ( ( front_limit_val != LIMIT_PRESSED ) &amp;amp;&amp;amp; ( twitch_state == NORTHSOUTH ) )&lt;br /&gt;
	{&lt;br /&gt;
		StopMotor();&lt;br /&gt;
		while (front_limit_val != LIMIT_PRESSED )&lt;br /&gt;
		{ &lt;br /&gt;
			PrintToScreen(&amp;quot;Twitch 255, state = %d&amp;quot;, (int)twitch_state); &lt;br /&gt;
			front_limit_val = GetDigitalInput ( FRONT_LIMIT ) ; &lt;br /&gt;
                            // Recieves input for the front limit switch&lt;br /&gt;
			SetPWM(TWITCH_MOTOR_1, 255);&lt;br /&gt;
			SetPWM(TWITCH_MOTOR_2, 0);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	if ( ( back_limit_val != LIMIT_PRESSED ) &amp;amp;&amp;amp; ( twitch_state == EASTWEST ) )&lt;br /&gt;
	{&lt;br /&gt;
		StopMotor();&lt;br /&gt;
		while (back_limit_val != LIMIT_PRESSED)&lt;br /&gt;
		{ &lt;br /&gt;
			PrintToScreen(&amp;quot;Twitch 0&amp;quot;);&lt;br /&gt;
			back_limit_val = GetDigitalInput ( BACK_LIMIT ) ; &lt;br /&gt;
                           // Recieves input for the back limit switch&lt;br /&gt;
			SetPWM(TWITCH_MOTOR_1, 0);&lt;br /&gt;
			SetPWM(TWITCH_MOTOR_2, 255);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	SetPWM(TWITCH_MOTOR_1,127);  // turn off the twitch motors &lt;br /&gt;
	SetPWM(TWITCH_MOTOR_2,127);&lt;br /&gt;
        // End of Twitch action&lt;br /&gt;
	&lt;br /&gt;
        // Diagnostic code to make sure we Twitched correctly&lt;br /&gt;
	PrintToScreen(&amp;quot;fl = %d , bl = %d state = %d, front = %d&amp;quot;,&lt;br /&gt;
            (int)front_limit_val,(int)back_limit_val, (int)twitch_state, (int)front); &lt;br /&gt;
} // End of CheckTwitch&lt;br /&gt;
&lt;br /&gt;
void x_DriveRobot(void)&lt;br /&gt;
/* This is our custom drive routine for arcade mode.  &lt;br /&gt;
   It was written as an adjunct to the routinge below that uses the WPILibrary Arcade mode.&lt;br /&gt;
*/&lt;br /&gt;
{&lt;br /&gt;
	unsigned char m_left, m_right;&lt;br /&gt;
	unsigned char stick_x, stick_y;&lt;br /&gt;
&lt;br /&gt;
	// Inputs are the X and Y stick&lt;br /&gt;
        stick_x = GetRxInput(1,1);&lt;br /&gt;
		stick_y = GetRxInput(1,2);&lt;br /&gt;
		m_left = (int) stick_y + ((int) stick_x - 127);&lt;br /&gt;
		m_right = (int) stick_y - ((int) stick_x - 127);&lt;br /&gt;
&lt;br /&gt;
		// need to get the value back in the range 0..254&lt;br /&gt;
&lt;br /&gt;
		if (m_left &amp;lt; 0) {&lt;br /&gt;
			m_left = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		if (m_left &amp;gt; 254) {&lt;br /&gt;
			m_left = 254;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		if (m_right &amp;lt; 0) {&lt;br /&gt;
			m_right = 0;&lt;br /&gt;
		}   &lt;br /&gt;
		if (m_right &amp;gt; 254) {&lt;br /&gt;
				m_right = 254;&lt;br /&gt;
		}&lt;br /&gt;
		switch (front) //Front has the &amp;quot;front&amp;quot; of the robot, which way to go&lt;br /&gt;
				{&lt;br /&gt;
			case NORTH: { // North&lt;br /&gt;
				SetPWM(MOTOR_2,m_right); // right side motors are 2 and 4&lt;br /&gt;
				SetPWM(MOTOR_4,m_right);&lt;br /&gt;
				SetPWM(MOTOR_1,m_left); // left side motors are 1 and 3&lt;br /&gt;
				SetPWM(MOTOR_3,m_left);&lt;br /&gt;
				PrintToScreen(&amp;quot;North &amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
            }&lt;br /&gt;
			case EAST: { // East&lt;br /&gt;
				SetPWM(MOTOR_4,m_right); &lt;br /&gt;
				SetPWM(MOTOR_3,m_right);&lt;br /&gt;
				SetPWM(MOTOR_2,m_left); &lt;br /&gt;
				SetPWM(MOTOR_1,m_left);&lt;br /&gt;
				PrintToScreen(&amp;quot;East &amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
            }&lt;br /&gt;
			case SOUTH: { // South&lt;br /&gt;
				SetPWM(MOTOR_3,m_right); &lt;br /&gt;
				SetPWM(MOTOR_1,m_right);&lt;br /&gt;
				SetPWM(MOTOR_4,m_left); &lt;br /&gt;
				SetPWM(MOTOR_2,m_left);&lt;br /&gt;
				PrintToScreen(&amp;quot;South &amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
            }&lt;br /&gt;
			case WEST: { // West&lt;br /&gt;
				SetPWM(MOTOR_1,m_right); &lt;br /&gt;
				SetPWM(MOTOR_2,m_right);&lt;br /&gt;
				SetPWM(MOTOR_3,m_left); &lt;br /&gt;
				SetPWM(MOTOR_4,m_left);&lt;br /&gt;
				PrintToScreen(&amp;quot;West &amp;quot;);&lt;br /&gt;
				break;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
} // End of x_DriveRobot&lt;br /&gt;
&lt;br /&gt;
void DriveRobot(void)&lt;br /&gt;
//  This makes the robot move. We cheat and use the WPILibrary calls&lt;br /&gt;
//  rather than doing the hard work of doing the motors&lt;br /&gt;
/*&lt;br /&gt;
This is the prototype function for the 4 wheel drive arcade. &lt;br /&gt;
&lt;br /&gt;
void Arcade4(unsigned char port,  // Which transmitter 1 or 2&lt;br /&gt;
            unsigned char ucMoveChannel, unsigned char ucRotateChannel, // which joystick channel &lt;br /&gt;
            unsigned char ucLeftfrontPWM, unsigned char ucRightfrontPWM,&lt;br /&gt;
            unsigned char ucLeftrearPWM, unsigned char ucRightrearPWM,&lt;br /&gt;
            unsigned char ucLeftfrontInvert, unsigned char ucRightfrontInvert,&lt;br /&gt;
            unsigned char ucLeftrearInvert, unsigned char ucRightrearInvert);&lt;br /&gt;
*/&lt;br /&gt;
{&lt;br /&gt;
switch (front) //Front has the &amp;quot;front&amp;quot; of the robot, which way to go&lt;br /&gt;
{&lt;br /&gt;
   case NORTH:{ // North&lt;br /&gt;
	Arcade4(1,&lt;br /&gt;
            2, 1,&lt;br /&gt;
            MOTOR_1, MOTOR_2,&lt;br /&gt;
            MOTOR_3, MOTOR_4,&lt;br /&gt;
            1, 1,&lt;br /&gt;
            1, 1);&lt;br /&gt;
		PrintToScreen(&amp;quot;North &amp;quot;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
   case EAST:{ // East&lt;br /&gt;
	Arcade4(1,&lt;br /&gt;
            2, 1,&lt;br /&gt;
            MOTOR_2, MOTOR_4,&lt;br /&gt;
            MOTOR_1, MOTOR_3,&lt;br /&gt;
            1, 1,&lt;br /&gt;
            1, 1);&lt;br /&gt;
		PrintToScreen(&amp;quot;East &amp;quot;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
   case SOUTH:{ // South&lt;br /&gt;
	Arcade4(1,&lt;br /&gt;
            2, 1,&lt;br /&gt;
            MOTOR_4, MOTOR_3,&lt;br /&gt;
            MOTOR_2, MOTOR_1,&lt;br /&gt;
            1, 1,&lt;br /&gt;
            1, 1);&lt;br /&gt;
		PrintToScreen(&amp;quot;South &amp;quot;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
   case WEST:{ // West&lt;br /&gt;
	Arcade4(1,&lt;br /&gt;
            2, 1,&lt;br /&gt;
            MOTOR_3, MOTOR_1,&lt;br /&gt;
            MOTOR_4, MOTOR_2,&lt;br /&gt;
            1, 1,&lt;br /&gt;
            1, 1);&lt;br /&gt;
		PrintToScreen(&amp;quot;West &amp;quot;);&lt;br /&gt;
		break;&lt;br /&gt;
	}&lt;br /&gt;
    }&lt;br /&gt;
} // End of DriveRobot&lt;br /&gt;
&lt;br /&gt;
void main(void)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	PrintToScreen(&amp;quot;Twitch\n\r&amp;quot;);     &lt;br /&gt;
        front = NORTH; // set direction&lt;br /&gt;
	twitch_state = NORTHSOUTH; // set intial twitch state&lt;br /&gt;
	// The robot will move to this state when it gets turned on&lt;br /&gt;
	// Issue is one match to another, what should the twitch state be?&lt;br /&gt;
        // Future code should have a jumper to check&lt;br /&gt;
    while (1){&lt;br /&gt;
	CheckTwitch();&lt;br /&gt;
	DriveRobot();&lt;br /&gt;
	PrintToScreen(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</description>
			<pubDate>Mon, 15 Jun 2009 11:06:44 GMT</pubDate>			<dc:creator>Foster</dc:creator>			<comments>https://stemrobotics.org/mediawiki/index.php/Talk:Twitch_Software</comments>		</item>
	</channel>
</rss>