Cy Think Survey

Stan 1.0

A balancing robot

Survey Home
Cy Think Home
Feedback
Contact
Search Content
Pictures
Stories
Tips
Classifieds
Essays
Help Index
Cobb County GIS
Stan
Practice Tests
Student Files
YourTest
CTC
Strayer
Strayer CIS105
Programming Concepts
Altura
Bible
1 and 1
Admin

An early version of the code used in Stan 1.0 and Stan 4.0.

#include "UserAPI.h"

int end = 0; 
int flag; 
int pend; 
int bump1; 
int bump2; 
int limit1; 
int limit2; 
int direction = 0; 

void main ( void )
{
      while ( end < 1 )
      {
            //  read inputs
            bump1 = GetDigitalInput ( 5 ) ;
            bump2 = GetDigitalInput ( 6 ) ;
            limit1 = GetDigitalInput ( 7 ) ;
            limit2 = GetDigitalInput ( 8 ) ;
            //  set direction
            if ( bump1 < 1 )
            {
                  direction = 1 ;
            }
            if ( bump2 < 1 )
            {
                  direction = -1 ;
            }
            if ( limit1 < 1 )
            {
                  if ( direction < 0 )
                  {
                        direction = 0 ;
                  }
            }
            if ( limit2 < 1 )
            {
                  if ( direction > 0 )
                  {
                        direction = 0 ;
                  }
            }
            //  determine outputs based on direction
            if ( direction > 0 )
            {
                  flag = 200 ;
                  pend =255 ;
            }
            else
            {
                  if ( direction < 0 )
                  {
                        flag = 50 ;
                        pend = 0 ;
                  }
                  else
                  {
                        flag = 125 ;
                        pend = 127 ;
                  }
            }
            //  flag controls position of the feedback flag
            SetServo ( 1 , flag ) ;
            //  pend controls movement of the inverted pendulum
            SetMotor ( 4 , pend ) ;
      }
}
Copyright © 2008 Cy Think, Inc.