|
Page 1 of 1
|
[ 3 posts ] |
|
Trouble programming NXT Robot
Author |
Message |
IndianCow
Rookie
Joined: Sat Jan 18, 2014 6:59 pm Posts: 2
|
 Trouble programming NXT Robot
I am having trouble making my robot controlling my Mindstorms NXT robot with RobotC. I want my robot to be able to move forward on a table and when reaching the end, the ultrasonic sensor, which is facing down, will determine if it is on the edge by seeing how far the ground is. When the ultrasonic sensor finds that it is on the edge, the robot will move back from the edge, turn around, and go the other way.
Here is my code:
#pragma config(Sensor, S1, , sensorSONAR) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
int Ultrasonic; Ultrasonic = SensorValue[S1]; while (true) { if (Ultrasonic >10) { motor[motorB] = -100; motor[motorC] = -100; wait1Msec(2000); motor[motorB] = 100; wait1Msec(2000); } if (Ultrasonic <= 10) { motor[motorB] = 50; motor[motorC] = 50; wait1Msec(5000); } } }
|
Sat Jan 18, 2014 7:00 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: Trouble programming NXT Robot
Might I suggest: Assigning the value of the Ultrasonic sensor is a good idea if you're going to be calling on it multiple times like that in the same loop. However, since you declared the variable and assigned the value outside of your loop, the variable value would never have changed. Although I can see how you'd think that, Ultrasonic = SensorValue[S1]; does not continually update the Ultrasonic value with the sensor value, only when you execute that command does it update the value. I also changed your motor control code a bit - change it back if you like, but this makes more sense to me with what you're trying to do.
_________________A.K.A. inxt-generation Self-proclaimed genius, and future world dominator. My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth Doctor Bow down to Nikola Tesla, King of the Geek Gods.
|
Sat Jan 18, 2014 7:07 pm |
|
 |
IndianCow
Rookie
Joined: Sat Jan 18, 2014 6:59 pm Posts: 2
|
 Re: Trouble programming NXT Robot
Thank you so much @NeXT-Generation! I just started programming in RobotC because I want to learn it before I go to high school so I can be on the robotics team.
|
Sat Jan 18, 2014 7:11 pm |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|