Until the Sensor Is Touched Again Robotc
Download

Skip this Video
Loading SlideShow in 5 Seconds..
RobotC – A Tutorial Ii PowerPoint Presentation
RobotC – A Tutorial Ii
Download Presentation
RobotC – A Tutorial 2
- - - - - - - - - - - - - - - - - - - - - - - - - - - Due east North D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
-
RobotC – A Tutorial 2
-
Learning from yesterday • The IDE • Functions and usage of various panels • Meridian Menubar • Side Functions panel • Code Window • Mistake Window • Compiling/Downloading the lawmaking • Running the program • C Programming Syntax • Capitalization • Whitespaces • Comments • Variables • Boolean Algebra REVISION
-
Learning from yesterday • Command Structures • Tasks • Functions • If-Else/Switch • While/For Today we are going to await at specific commands and options bachelor in RobotC for decision-making the NXT REVISION
-
Department Overview • Reserved Words Motors Timers LCD Display • Sensor Configuration • Debugger Usage Tasks Functions If-Else/Switch While/For Section iii
-
Overview • RobotC has a diversity of commands, interfaces and options which deal specifically with robots. Some of these are • Reserved words similar motor, timers (keywords) • Sensor interfaces • Live debugger ROBOTC FEATURES
-
Keywords • RobotC has a variety of keywords which are used for issuing specific commands to the NXT controller • As it is not possible to encompass all the commands in detail here, only the main ones will be discussed. • Explore the rest of the options by using the aid available inside the programming environs or online version (as explained before) ROBOTC FEATURES
-
Motors Motor command – Turn on/off at a sure power level Full general Syntax motor[output] = power; Parameters Output – Determine the motor to affect. This can be motorA, motorB, motorC This command just gives power to the 3 output ports A, B, C in a certain style. This can also be fed to a circuit to command other devices Power – Determines the ability at which the motor is to exist run. This tin take whatsoever integer value from -100 (full reverse) to 100 (full forwards) Examples motor[motorA] = 60; //Run motor A at lx% power motor[motorB] = -l; //Run motor B in reverse at 50% motor[motorC] = 100; //Run motor C at full power forwards ROBOTC FEATURES
-
Motors – five infinitesimal activeness Using the unproblematic motor command, endeavour to write a programme that spins the RoboCar every bit fast as possible How fast does information technology rotate? (RPM) ROBOTC FEATURES
-
Motors – five minute activeness How did you lot exercise? Hither is one solution: chore master() { motor[motorA] = 100; motor[motorB] = -100; while(true); } …where you lot turn both motors at full power, opposite direction. At this point, just have a moment to recollect of all the other factors which may have affected your spin rate (bombardment power, weight imbalance, friction, etc) Robust code accounts for every bit many uncertainties as possible ROBOTC FEATURES
-
Timers – Wait Timers The expect commands allow you to insert delays into your program. Its like starting a stop watch and pause the execution of your plan. The pause in execution means that the next command will not be executed till after the timer expires. Yet, the actions due to the commands already issued will continue. There are 2 commands related to this wait1Msec(wait_time); wait10Msec(wait_time); Parameters wait_time – Refers to the fourth dimension for which the program pauses earlier proceeding to the adjacent step. The units are either milliseconds (ane/yard of sec) or 10s of milliseconds (1/100 of sec) ROBOTC FEATURES
-
Timers – Examples The post-obit examples uses the await office to permit the motors to operate for 1 second at a time. ROBOTC FEATURES
-
Motors – 5 infinitesimal activity Using the await command, try to write a program that rolls the car forward a distance of approximately 2 anxiety ROBOTC FEATURES
-
Motors – 5 minute activity How did you practice? Does your code look something similar this? task main() { motor[motorA] = 100; motor[motorB] = -100; wait1Msec(2000); // however long it takes to go 2ft } ROBOTC FEATURES
-
LCD Display • The LCD display on the NXT is a 6 line display that can exist controlled via functions in RobotC. • It tin support a brandish of sixteen characters per line • The display is an extremely useful resources during the debugging phase, for observing the values of diverse inputs and outputs. • If left unmodified, the LCD will display the readings of the input sensors and the output ability level of the motors. ROBOTC FEATURES
-
LCD Brandish - Functions 2 functions that may be useful to access the LCD are nxtDisplayStringAt(xPos,yPos,text,var1,var2,var3) – impress text eraseDisplay()– clear the NXT display Parameters xPos - Number of pixels abroad from the left of the display that you want your string to be printed at. yPos - This integer value is the number of pixels away from the bottom of the display that yous want your cord to be printed at. text - The text parameter is what shows up on the screen. This will be a string enclosed in quotes up to 16 characters. You may also display up to iii variables in this string by adding %d, %f (conversion specifications) up to iii times. var1, var2, var3 - These (optional) parameters define which variables will exist displayed to the screen and each must correspond to a split up %d, %f within the text parameter. ROBOTC FEATURES
-
Motors - Encoder Each standard Lego motor has an inbuilt encoder that can be used to measure out the amount the motor has turned by, or turn the motor past a specific number of degrees Full general Syntax (to obtain the reading) myVar =nMotorEncoder[output] General Syntax (set the turning amount) nMotorEncoderTarget[output] = numCounts Parameters output – Decide the motor to affect. numCounts – The number of encoder counts that the motor must turn earlier stopping myVar – a variable that gets assigned the current value of the encoder ROBOTC FEATURES
-
Motors - Encoder Encoder Example (To turn to desired value by setting) // Fix degrees that motor A must plow to thou nMotorEncoderTarget[motorA] = one thousand; // Turn on Motor A. It will automatically finish // after turning for the desired amount motor[motorA] = 75; ROBOTC FEATURES Encoder Instance (To turn to desired value by observation) // Turn on motorA until it has turned 1000 degrees motor[motorA] = 75; while(nMotorEncoder[motorA] <= 1000) ; // practice zippo motor[motorA] = 0; // requires explicit terminate
-
Motors – 10 infinitesimal activity Write a artistic programming solution to navigate the following course – without using any sensors. Based on what you have already learned ROBOTC FEATURES 1 ft one ft 1 ft 1 ft 1 ft 2 ft ( note: 1 ft = 0.3048 m)
-
Motors – x minute activity Here are a couple of suggestions Go straight for a fixed time (calculated by trial and error) Then turn right and get further direct for some more fourth dimension (once again calculated by trial and error) Then turn left and go straight OR Mensurate the circumference of the wheel to get how much the car will travel in one revolution. Use this number and the distances mentioned on the track to get the desired number of revolutions earlier turning Set the encoder accordingly and GO! OR Mix the to a higher place 2 methods ROBOTC FEATURES
-
Sensor Interface • RobotC has an extremely powerful sensor interface which may exist used to communicate with Lego and other tertiary party sensors. • Ideally, RobotC sensor interface provides an enormous degree of liberty to the programmer. • Information technology provides several options for configuring the sensor ports to • Read the raw value – Mainly used for self designed sensors • Communicate via the I2C interface – Mainly used by third party providers • Work using standard protocols and thresholds with the standard Lego sensors ROBOTC FEATURES
-
Sensor Interface - Accessing The sensor interface in RobotC may be accessed through the Robot Menu on top of the IDE. The steps for accessing the sensor menu are as follows ROBOTC FEATURES Click on the Robot Button on the height menubar and select the Motors and Sensors Setup box
-
Sensor Interface - Accessing Click on the direction tab. This brings up the options to select the kind of sensors that are displayed ROBOTC FEATURES Tick the bottom 3 boxes. Unless you want to apply old RCX Sensors
-
Sensor Interface - Accessing A popup will occur every bit depicted. Cull the A/D sensor tab. A/D stands for Analog to Digital ROBOTC FEATURES Type of sensors You tin configure upwards to 4 sensors Fields for specifying the names of the sensors
-
Sensor Interface - Accessing Give a name to the sensors you intend to use and configure it to a certain type from the drop box ROBOTC FEATURES Type of sensors This one is being configured every bit SONAR names given to the three sensors
-
Sensor Interface - Accessing Click on OK. This will create some auto-generated lines of code at the top of the program. This ways that the sensors take been configured for apply in the program. ROBOTC FEATURES Discover, No line numbers Auto-generated code. DO NOT EDIT THIS Given sensor names
-
Sensor Interface - Accessing Afterward configuration, using the sensor values in the program is a piddling task — two methods of obtaining the sensor values: myVar = SensorValue(sensor_name) myVar = SensorRaw(sensor_name) The first method returns the configured sensor value. Second i returns the raw value. Parameters sensor_name – This denotes the name assigned to the sensor in the configuration step Both may be used to obtain sensor readings (either raw or calibrated) The choice of method depends upon intended use ROBOTC FEATURES
-
Sensor Interface Each sensor after configuration has ii types of values Raw value – This is the raw value that the NXT observes based on the voltage across the input port. Every sensor has a raw value reading. Varies between 0-1023 (x $.25) Sensor Value – Obtained later on application of thresholds to the raw value based on the configuration. Range depends on the configuration. More apt every bit per application Example: For a sensor configured equally a bear on sensor ROBOTC FEATURES
-
Sensors – 10 min activeness Configure the sensor on port 1 to exist a light sensor. Write a snippet of lawmaking that looks at the sensor reading and displays a "Lite!" or "Night!" message on the NXT screen when the low-cal sensor is over a lite or dark surface. ROBOTC FEATURES
-
Sensors – 10 min activity Did your programme look like this?? #pragma config(Sensor,S1,LightSensor,sensorLightActive) //*!!Code automatically generated by 'ROBOTC' configuration sorcerer !!*// int lightvalue; job master() { while(true){ lightvalue =SensorValue(LightSensor); if(lightvalue >45) { nxtDisplayStringAt(1,xx,"Light!"); }else{ nxtDisplayStringAt(1,20,"Nighttime!"); } } } ROBOTC FEATURES
-
Debugging Debugging is one of the well-nigh difficult parts of writing code Fortunately, RobotC has an extremely powerful debugger, much amend than other languages for similar functions ROBOTC FEATURES
-
Debugger – Not Compiler Debugging generally refers to solving logical fallacies in the code. The compiler will give ERROR messages ONLY for syntax errors. You cannot run a code with syntax errors The compiler does highlight potential logical flaws in the course of WARNINGS and INFO messages. But these MAY or MAY NOT be the source of the logical problems. It is a good practise to make sure you take stock-still all alert and info letters too. ROBOTC FEATURES
-
The Debugger Window Start/Stop Programme Suspend (pause) or Resume Update debugger display windows (once) ROBOTC FEATURES Update display windows (continuously) Warning: Can wearisome program execution! Line-by-line code execution (see actress slides for more than details)
-
Debugging - Options Compiling and loading the program on the brick will enable several new debug options which were previously disabled or inactive Each of these windows is pregnant for a detail kind of error tracking The most important ones are ane. Global Variables 2. NXT Devices 3. Task Status ROBOTC FEATURES
-
Debugging Windows } Global Variable Values ROBOTC FEATURES Sensor Values
-
Debugging – 5 minute activity Using the program that you wrote in the last activity, use the debugger to detect the changing sensor values and the changing "lightvalue" variable equally you lot move the NXT to different lighting conditions. ROBOTC FEATURES
-
Summary • In the final section, you learned • RobotC specific keywords and usage • Sensor configuration and usage • Basic use of the debugger • This completes the basic tutorial on RobotC. • You should now be familiar plenty with the basic concepts to build sufficiently complex systems SECTION SUMMARY
-
Help • In example you need aid • Have a look at http://www.robotc.internet/teachingmindstorms/ • Apply the in-built help in the IDE • Ask Google • If y'all are still stuck, ask your TF/TA!!! • …and like mentioned initially, always remember - your blueprint and needs should guide the language and not the other manner effectually!! SECTION SUMMARY
-
Questions??? • QUESTIONS
-
Debugging - Instance Consider the instance on the side by side slide for the purpose of debugging There are intentionally created errors in that plan Lets see if they can be identified using the debugger ROBOTC FEATURES
-
ROBOTC FEATURES
-
Debugging What errors can exist identified from here?? This variable is not existence updated, so mustn't exist assigned ROBOTC FEATURES These variables have identical values assigned, merely according to sensors; they should be different More clues …
-
Lets run into how accurate we were variable light_sensor is not assigned ROBOTC FEATURES variable dist_sensor is getting light_sensor reading Thus we were correctly able to identify all errors
-
Debugging Lets see how the debugger looks with the corrected programs ROBOTC FEATURES All seem good and in correspondence PERFECT!!!
-
Lets right the program Observe the colour of these X's. Recall from yesterday. These are simple information letters. Why do yous call back they are reported? The compiler is trying to tell y'all that though you have declared and assigned these variables, you take not used them anywhere in the program. So it is trying to save your retention and flag potential errors. Sometimes, you tend to declare a variable with the intention of using it merely finish up using the wrong variable with a similar name. This can lead to really unpredictable results. One of the most hard logical errors to catch ROBOTC FEATURES
-
Debugging One of the major sources of issues is disconnection of an input sensor from the port, either due to a loose connection, or inadvertent connection to the incorrect port In this instance, the lite sensor from port A is connected mistakenly to port C Find how the raw value of port A is saturated at 1023 while there is an undesired value on port C ROBOTC FEATURES
-
Debugging One common problem with many codes is missing timing delays. Such mistakes cause a lot of confusion and undesirable results These are difficult to catch past using the debugging techniques discussed They can exist improve examined by using the step by step debugger of RobotC ROBOTC FEATURES These commands permit step past step execution, hence giving more command for analysis
-
Debugging - Example Consider a plan that moves the car forward till the light sensor reading is in a higher place a threshold (i.e. it is bright). If information technology sees a shadow, or darkness, i.e. the value of the light sensor drops, it backs up for some distance and then tries again ROBOTC FEATURES This program has the mistake that as soon every bit the car sees the blackness line or black shadow, it stops rather than going back.
-
Debugging - Example Lets try to use the debugger stepping to solve the trouble. We can run into that if we select continuous update of the values, then the green line moves extremely fast and nosotros are unable to understand anything. ROBOTC FEATURES
-
Debugging - Example The mode around this is to suspend the programme by clicking the append button. This pauses the execution of the programme leaving all the variables and sensors intact The sensor readings and motor tachometer readings keep getting updated even in the suspend mode ROBOTC FEATURES Then click the step into button. This will cause the greenish line to exist replaced past a xanthous 1 which will stay on a specific argument You are at present using the stepping mode of the debugger
-
Debugging - Example Each successive pressing of the Stride Into button volition accelerate the program step by step ROBOTC FEATURES
Source: https://www.slideserve.com/brandonstewart/robotc-a-tutorial-ii-powerpoint-ppt-presentation
0 Response to "Until the Sensor Is Touched Again Robotc"
Post a Comment