RobotC - Lego NXT & RobotC A warning - Going forward,...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Lego NXT & RobotC
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A warning… - Going forward, the RobotC questions on assignments HAVE to be done during the lab as we verify that your code is working during a “demo” - If you haven’t read the assignment before you show up, you WILL run out of time. ..
Background image of page 2
Mechatronics -Introduction to Mechatronics - Discipline where Mechanical and Electrical Engineering intersect - From mechanical: the physical device, including the mechanics of movement - From electrical: actuators, sensors, power electronics and microprocessors - Lego NXT is an approachable system to learn about these topics
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mechatronics - Why are you learning this? - Microprocessors interact with the physical world in virtually everything - Provides a means of examining programming and problem solving in a totally different context - Why not!? It’s Lego!!
Background image of page 4
Mechatronics Processor Sensors or Transducers Motors or Actuators Interface Interface Convert to Digital Convert to Analog Current or Voltage
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lego NXT Brick • Brick has: 32 bit microprocessor @ 48 MHz • 3 outputs for motors • 4 sensor inputs Picture: http://mindstorms.lego.com/en-gb/history/default.aspx
Background image of page 6
Lego NXT Brick • Each kit has 3 motors, 2 push buttons, 1 colour sensor,1 ultrasonic sensor and 4 buttons on the brick itself
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
RobotC • A C based language designed to be used to program robotic kits such as Lego NXT • Programmed using an IDE (Integrated Development Environment) www.robotc.net/ – You can download yourself, but only a 30 day trial
Background image of page 8
RobotC IDE Screen shot by Carol Hulls
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
RobotC IDE Screen shot by Carol Hulls
Background image of page 10
RobotC vs. C++ • Size of memory (RobotC has 64k=65536 bytes) • No library declarations • Main is a task – (eg. task main() ) • Input/Output is different • No double, only float • Specific constants, variables and functions that are RobotC only http://sherryfowlerchancellor.files.wordpr ess.com/2010/05/rockem.jpg
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lego NXT Display • 100 x 64 pixel LCD • 8 lines for outputting text • C++ output: cout <<“Hello”; • For RobotC, you need to specify the line you are printing to: – Ex. nxtDisplayString (0,”Hello”); Line number Message string
Background image of page 12
Outputting Variables in RobotC • C++: int a=5; cout <<“a= “<<a; - In RobotC, outputting variables is more like old C - “placeholders” are needed - Ex: int a=5; nxtDisplayString (2,”a= %d”,a ); - %d for int, %f for float, %s for string Screen output Line # variable
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Hello World Example Ex: task main() { eraseDisplay(); nxtDisplayString (0,”Hello”); nxtDisplayString (2,”World!”); wait1Msec(5000); } Clears everything off the display
Background image of page 14
Output Formatting C++ • If we want to have the output display 2 decimal places, we use the following: cout<<fixed<<setprecision(2); • And if we want to format nice columns for a table, we use setw(): cout<<setw(10)<<outputVar1<< setw(15)<<outputVar2<<endl; 1 st column is 10 characters wide 2nd column is 15 characters wide Global change
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Output Formatting RobotC • If we want a variable to display with 2
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 73

RobotC - Lego NXT &amp; RobotC A warning - Going forward,...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online