Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

102 lines (82 sloc) 3.593 kb
// ----------------------------------------------------------------------- INCLUDES
// ----------------------------------------------------------------------- SYNOPSIS
#include "sound.h"
#include "display.h"
#include "odometry.h"
#include "beep_task.h"
// --------------------------------------------------------------------------------
/************** DEFINES *******************************************************/
#define MOVE_STRAIGHT_TIME 2000
/************** Procedure *****************************************************/
/************** TASKS *********************************************************/
task move_square()
{
int random_number = Random(600); // creates random number between 0 and 600
// drive 3 squares
for(int i=0; i < 3; i++)
{
// drive four times a straight line and a 90 degree turn
repeat(4)
{
// power on both motors to move straight
OnFwd(OUT_AC, 50);
// wait for a certain time so that the robot can move a bit
Wait(MOVE_STRAIGHT_TIME);
//turn on the spot
OnRev(OUT_A, -50);
OnRev(OUT_C, 50);
Wait(500);
}
}
// turn both motors off
Off(OUT_AC);
}
task display_sensor_values()
{
int color_value=0;
int r=0, g=0, b=0;
while(TRUE)
{
float angle = getAngle();
float distance = getDistance();
TextOut(0, LCD_LINE1, "Sensor Values:"); // outputs text in the first row of the LCD display
TextOut(0, LCD_LINE2, "US 1:");
NumOut(50, LCD_LINE2, SensorUS(IN_1)); // outputs first ultrasonic sensor values in the 2. row of the LCD display
TextOut(0, LCD_LINE3, "US 2:");
NumOut(50, LCD_LINE3, SensorUS(IN_2)); // outputs second ultrasonic sensor values in the 3. row of the LCD display
TextOut(0, LCD_LINE4, "Light:");
NumOut(50, LCD_LINE4, Sensor(IN_3)); // outputs light sensor values in the 4. row of the LCD display
TextOut(0, LCD_LINE5, "color:");
ReadSensorHTColor(IN_4, color_value, r, g, b);
NumOut(50, LCD_LINE5, color_value); // outputs color sensor values in the 5. row of the LCD display
TextOut(10, LCD_LINE6, "r:");
NumOut(50, LCD_LINE6, r); // outputs color sensor values in the 6. row of the LCD display
TextOut(10, LCD_LINE7, "g:");
NumOut(50, LCD_LINE7, g); // outputs color sensor values in the 7. row of the LCD display
TextOut(10, LCD_LINE8, "b:");
NumOut(50, LCD_LINE8, b); // outputs color sensor values in the 8. row of the LCD display
Wait(250);
ClearScreen();
}
}
task test_odometry()
{
while(TRUE)
{
display_odometry(getDistance(), getAngle());
Wait(100);
}
}
task main()
{
SetSensor(IN_1, SENSOR_LOWSPEED); // ultrasonic sensor is connected to the nxt port 1
//SetSensor(IN_2, SENSOR_LOWSPEED); // ultrasonic sensor is connected to the nxt port 2
//SetSensor(IN_3, SENSOR_LIGHT); // light sensor is connected to the nxt port 3
//SetSensorType(IN_3, IN_TYPE_LIGHT_ACTIVE); // set active light sensing
///SetSensor(IN_4, SENSOR_LOWSPEED); // color sensor is connected to the nxt port 4
//SetSensor(IN_4, SENSOR_LIGHT); // light sensor is connected to the nxt port
Precedes(test_odometry);
//Precedes(display_sensor_values);
ResetTachoCount(OUT_AC);
Precedes(beep_if_red);
}
Jump to Line
Something went wrong with that request. Please try again.