Top Banner
RobotC Language Guide Mr. Michaud Marist School
18

RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Aug 02, 2018

Download

Documents

hoangkien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

RobotC Language Guide

Mr. Michaud Marist School

Page 2: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands • Task main() • Data Types • Assigning Variables • Reading Sensor Values • Conditionals • While Loops • Functions • Operators • For Loops

Page 3: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Comments

• Lines of text with purpose to inform human reader of program content and intent

• Vital for collaboration (and grade!)

Page 4: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Configuration

• Motors and Sensors must be configured with #pragma commands. This is done using the Motors and Sensors Setup option.

Page 5: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Motor Commands

Page 6: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Timing Commands

Page 7: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Task Main Function

• All RobotC programs must have a task main() function. The robot software will begin in the task main() to run commands.

Page 8: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Data Types and Variables

Page 9: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Reading Sensor Values

Page 10: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Control Statements with Conditionals

if (condition) { // Response } while (condition) { // Actions }

Page 11: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Touch Stop While Statement

Page 12: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Encoder Wait

Page 13: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Declaring Functions and Tasks

• Task: Set of commands that can run concurrently

• Function: Encapsulates a set of commands – Void Functions: Perform a set of actions, but do

not return a value – Return Functions: Perform calculations or

measurements, and then return a value

Page 14: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Void Function Example

Page 15: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Return Function

Page 16: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Calling a Function

Page 17: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

Operators

Page 18: RobotC Language Guide - NeboMusic: Music and …nebomusic.net/robotclessons/robotc_intro.pdf · Elements of RobotC • Comments • Configuration • Motor Commands • Timing Commands

For Loop

• Executes a series of code more than once. Uses an ‘index’ variable to count the cycles