Page 1 of 1

NXT Programming help

Posted: 28 Mar 2013, 22:38
by john6672
hello guys, i need to build a C programming code for NXT to perform following tasks. I made an outline for it and would appreciate help in building the actual code. suggestions and hints to begin the logic would be very helpful. Following are the requirements :

Code: Select all

1. The Robot will roam randomly inside an arena which is defined by a
coloured boundary.(color : green) The robot should have an automatic calibration
mechanism that allows you to quickly calibrate the light sensor using
the buttons on the front of the robot.

2. If the robot encounters the arena perimeter it must backup and then
turn randomly and head off in another direction.

3. The robot must, while inside the arena, avoid obstacles that are placed
in the arena.

4. The robot must perform these operations for 1 minute at which point it
must stop and display some statistical results (as detailed below)
collected while roaming.

NOTE: The readings must be taken at 1 second intervals unless the
Robot is manoeuvring, in which case logging can stop until the
manoeuvre is complete.


OUTLINE OF THE PROGRAM
------------------------------------------

Sensors declaration

task main

declare variables
wait 1 sec

while true

int random roaming variables declaration

During 1 minute : - read all sensor's values every sec
		  - if sensor value light = silver or black : motors = random values for 1sec
                  
                  - if sensor value light = green : stop stats counting backoff , turn randomly, head off in another       

                     direction, continue stats counting.

                  - if sensor value sonar detects object : stop stats counting, count 1, obstacle,                         

                     backup , turn randomly, head direction, continue stats counting.

After 1 minute :  - stop

                  - display "run complete"

		  - display max and min values for each sensor

		  - display tot number of readings taken
		
		  - wait a bit

		  - display a graph


5. Statistics
a. While roaming you must take a reading of how much:-

i. Light is reflected by the surface of the arena.
ii. Background noise there is.
iii. The distance an obstacle is in front of the robot

b. On first stopping the robot must display a screen stating that the
run is complete and the maximum and minimum light, sound
and distances read during the run and also the total number of
readings taken (NOTE: this will vary based on how many times
the robot avoids an obstacle and the arena perimeter).

c. The statistics must then be displayed as a graph (The type of
graph is up to you) with the sensor reading type displayed in text
across the middle of the graph.

d. On pressing the right arrow key the screen must change to
display the graphs one at a time. There should be two graphs for
each sensor displaying:-

i. Readings in the sequence read during the run for: Light,
Sound and Distance.
ii. Readings sorted in ascending order for Light, Sound and
distance Distance


Re: NXT Programming help

Posted: 29 Mar 2013, 11:02
by pbenco
Hello dear john6672

0 - Have you read the FAQ, and search across the forum??? This sort of question has been replied lots of time

1 - Which C?
RobotC(fast and powerfull, source code not available, , good documentation, but licence cost),
NXC (free of charge, efficient and well supported), lots of ressources on the web -> google is your friend!!!
Microsoft Robotics SDK with C++(free of charge, tethered to a Computer and bluetooth),
NXTOSEK (Realtime kernel , expert skills demanding!!!),
GCC Arm toolchain (direct access to the machine code, but not friendly to set up and !!!)
IMHO, I would urge you to try NXC, you will find everything in term of programming environnement you will need. You seems new to NXT, if not in C programming... you need friendly and "out of the box" working programming tools compilation, what NXC provide.

2- We will NOT do your homework for you! You will generate more replies, in posting already partially working code, and real problems. Browsing/searching the forum, YOU will find answers to all questions around random implementation /calibration of the light sensor automatically /obstacle avoidance (US sensor?) / "sumo" ring perimeter detection /data collecting and displaying.

3- In the case you don't know were to begin: download and Install NXC, Flash the enhanced firmware, read the help and tutorial NXC pdf, and experiment!!!

Best regards
Ben

Re: NXT Programming help

Posted: 30 Mar 2013, 17:23
by john6672
yes am working on RobotC. I am already working on the code and will report back here if i have specific questions. thanks for the useful info!!