tu storm the tu storm robot controller: innovation first mini robot controller (microchip...
DESCRIPTION
● Start MPLAB IDE ● File -> Open Workspace… ● Select the.mcw file from the TU-STORM project you downloaded. ● Double-click user_routines.c in project window. ● Scroll down and edit Default_Routine(). ● Project -> Make ● Verify BUILD SUCCEEDEDTRANSCRIPT
TU STORM
The TU STORM Robot Controller:Innovation First Mini Robot Controller
(Microchip PIC18F8520)Programmable in CUsing MPLAB IDE
Installing MPLAB● Use C-Bot CD to install:● Step 1: MPLAB IDE● Step 2: C18 Compiler● Download IFI Loader from
TU-STROM Web site and install it.
● Download default TU-STORM Project code for TU-STORM Web site.
● Start MPLAB IDE● File -> Open Workspace…● Select the .mcw file from
the TU-STORM project you downloaded.
● Double-click user_routines.c in project window.
● Scroll down and edit Default_Routine().
● Project -> Make● Verify BUILD SUCCEEDED
Download Code to Robot Controller
● Connect serial cable from PC to IFI Controller.● Power up IFI Controller● Start IFI_Loader.● Browse to find the .hex file that was just compiled.● Click DOWNLOAD.
Why C?
● Modular● Powerful● Industry standard● Fast and efficient
TU-STROM Project● .c -Source Files● .h -Header Files● .lib -Library Files● .lkr -Linker Scripts● Edit the .c and .h files● Compile● Link TUStormCode.hex
Variables in C
unsigned char left_motor; /* range: 0 to 255 */
char left_motor; /* range: -128 to 127 */
unsigned int Left_BW_Sensor; /* range: 0 to 65535 */
int Left_BW_Sensor; /* range: -32768 to 32767 */
C is case-sensitive
int left_motor;
(is not the same as)
int Left_motor;
Assignments= operator
Shoulderx = 0.0;
count = count + 1;
General assignment:
variable_name = expression ;
Arithmetic Operations
C arithmetic operators: + , - , *, /
Can group together expression with parentheses.
result = (a + b) * c;
Control Structures
if ( condition ) { ... ... // The "then" block of statements. ... } else { ... ... // The "else" block of statements. ... }
Control Structures
if ( condition_1 ) { ... ... <-- "then" block_1; ... } else if ( condition_2 ) { ... ... <-- "then" block_2; ... } else { ... <-- "else" block; }
Conditionals
Conditionals are either true or false. Conditionals <- relational / logical operators. Relational operators: ==, !=, >, <, >=, <=.
logical operators: &&, ||, and !
Control Structures
if ((TopSw==ON)&&(MidSw==OFF)&&(BotSw==OFF)){ if ((RightBW < RgtBWThreshold) || (Flag == 1)){ RightMotor = RightIdle; LeftMotor = LeftIdle; } else { RightMotor = RightIdle + Speed; LeftMotor = LeftIdle - Speed; }}
Definition of C Functions
return_value_type func_name( declaration_of_arguments list ){ ... return_value_type return_value; // declare return value variable and type ... . //Block of function statements. ... return return_value;}
Sample Function
int Doubled_Number(int num2double ){ unsigned int result; // Local variable result = 2 * num2double; // Funtion Calculations return result; // Return value}
Output to the Screen
printf() command to display the values of Lmotor, Rmotor.
/* printf example */ unsigned char Lmotor, Rmotor;....printf("Lmotor = %d, Rmotor = %d\n", (int)Lmotor,(int)Rmotor);
Note: (Lmotor, Rmotor) are of type unsigned char. Must be typecast as int to work with printf().