View unanswered posts | View active topics It is currently Tue Sep 16, 2014 1:32 pm






Reply to topic  [ 14 posts ] 
What is a 4-stage ultrasonic movement command? 
Author Message
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post What is a 4-stage ultrasonic movement command?
what is a 4-stage ultrasonic movement command?
i am having difficulties writing a 4 stage movement command all i can do is write a 1-stage command...please HELP!!!


Mon Oct 22, 2012 2:21 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: What is a 4-stage ultrasonic movement command?
Can you describe what you want to do a little more clearly? What do you mean by 4-step ultrasonic command?

_________________
sudo rm -rf /


Mon Oct 22, 2012 2:44 pm
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
its a simple ultrasonic command, just be able to work 1 after the other 4 times in a row


Tue Oct 23, 2012 2:54 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: What is a 4-stage ultrasonic movement command?
I'm sorry, I still don't understand what you mean. Are you trying to describe something like:
Go forward until 20 cm away from wall
Turn right.
Got forward until 50 cm away from wall
Turn left.

_________________
sudo rm -rf /


Tue Oct 23, 2012 3:09 pm
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
YES thats exactly wat im trying to say, i got my robot to go forward untill it got to like, 40cm then turn left...but it didnt do anything else...even though there were still 3 more simple moving forward and turning left/right commands
...think u can just write me a sample program? ppllzz?
;D


Tue Oct 23, 2012 6:39 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: What is a 4-stage ultrasonic movement command?
Can you post the code that you already have written? It'll be a lot better if we can work from what you already have.

_________________
sudo rm -rf /


Tue Oct 23, 2012 6:57 pm
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
*sigh* ya i shall get it on here by 10/23/12
(its at school) by the way i appreciate you responding to my thread and attempting to help me


Wed Oct 24, 2012 12:41 am
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
Code:
#pragma config(Sensor, S4,     sonarSensor,         sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*--------------------------------------------------------------------------------------------------------*\
|*                                                                                                        *|
|*                                   - Obstacle Detection with Sonar -                                    *|
|*                                            ROBOTC on NXT                                               *|
|*                                                                                                        *|
|*  This program runs your robot forward until it detects and obstacle, at which point it stops.          *|
|*                                                                                                        *|
|*                                        ROBOT CONFIGURATION                                             *|
|*    NOTES:                                                                                              *|
|*    1)  The Sonar Sensor should be somewhere on the FRONT of the robot, facing FORWARD.                 *|
|*                                                                                                        *|
|*    MOTORS & SENSORS:                                                                                   *|
|*    [I/O Port]              [Name]              [Type]              [Description]                       *|
|*    Port B                  motorB              NXT                 Right motor                         *|
|*    Port C                  motorC              NXT                 Left motor                          *|
|*    Port 4                  sonarSensor         Sonar Sensor        Front mounted, front facing         *|
\*---------------------------------------------------------------------------------------------------4246-*/


task main()
{
  int distance_in_cm = 40;   // Create variable 'distance_in_cm' and initialize it to 20(cm).

   while(SensorValue[sonarSensor] > distance_in_cm)   // While the Sonar Sensor readings are less than the specified, 'distance_in_cm':
   {
      motor[motorB] = 75;                     // Motor B is run at a 75 power level
      motor[motorC] = 75;                     // Motor C is run at a 75 power level
   }
   motor[motorB] = 75;    // Motor B is stopped at a 0 power level
   motor[motorC] = 75;    // Motor C is stopped at a 0 power level

   motor[motorD] = 0;
   motor[motorE] = 50;
   wait1Msec(1000)      //90 degree turn

   motor[motorD] = 75;
   motor[motorE] = 75;
   wait1Msec(2000);

   motor[motorD] = 0;
   motor[motorE] = 50;
   wait1Msec(1000);     //90 degree turn

    int distance_in_cm = 70;  //2nd sonar command ( i dont know how to even get this 1 to work, i think
                              //                   ( i need the WHILE command)
    {
    motor[motorD] = 75;
    motor[motorE] = 75;

   //more to come



   }


Wed Oct 24, 2012 12:59 am
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
i had to remake this command so its not the actual thing, i can get the actual thing tomarrow while as im at school, but for now u can have that to mess around that till i post the actual command list tomarrow while im at school


Wed Oct 24, 2012 1:01 am
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
just like i promised bro, here is the exact command list that we have, any assistance is GREATLY appreciated:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S4,     sonarSensor,    sensorSONAR)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*--------------------------------------------------------------------------------------------------------*\
|*                                                                                                        *|
|*                                   - Obstacle Detection with Sonar -                                    *|
|*                                            ROBOTC on NXT                                               *|
|*                                                                                                        *|
|*  This program runs your robot forward until it detects and obstacle, at which point it stops.          *|
|*                                                                                                        *|
|*                                        ROBOT CONFIGURATION                                             *|
|*    NOTES:                                                                                              *|
|*    1)  The Sonar Sensor should be somewhere on the FRONT of the robot, facing FORWARD.                 *|
|*                                                                                                        *|
|*    MOTORS & SENSORS:                                                                                   *|
|*    [I/O Port]              [Name]              [Type]              [Description]                       *|
|*    Port B                  motorB              NXT                 Right motor                         *|
|*    Port C                  motorC              NXT                 Left motor                          *|
|*    Port 4                  sonarSensor         Sonar Sensor        Front mounted, front facing         *|
\*---------------------------------------------------------------------------------------------------4246-*/


task main()
{
  int distance_in_cm = 25;   // Create variable 'distance_in_cm' and initialize it to 20(cm).

   while(SensorValue[sonarSensor] > distance_in_cm)   // While the Sonar Sensor readings are less than the specified, 'distance_in_cm':
   {
      motor[motorD] = 30;                     // Motor B is run at a 75 power level
      motor[motorE] = 30;                     // Motor C is run at a 75 power level

   motor[motorD] = 0;    // Motor B is stopped at a 0 power level
   motor[motorE] = 0;    // Motor C is stopped at a 0 power level

     motor[motorD] = 0;
     motor[motorE] = 50;
     wait1Msec(1000);




   }
}


Wed Oct 24, 2012 1:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: What is a 4-stage ultrasonic movement command?
I don't understand what you are trying to do. According to your code, you are programming the pair of motors to three different behaviors (1. move forward at 30% power; 2. stop; 3. turn), at the same time. So only the last behavior will stick. Therefore, what you will see is the robot is turning all the time as long as there is no obstacle within 25cm.
If I have to guess what you want to do, it is probably something like this:
Code:
task main()
{
    while (true)
    {
        if (SensorValue[sonarSensor] > distance_in_cm)
        {
        }
        else if (some_other_condition)
        {
        }
        else
        {
        }
        wait1Msec(100);
    }
}

Since I don't know your intended behavior, I did not put in any action code.


Wed Oct 24, 2012 1:52 pm
Profile
Novice
User avatar

Joined: Mon Oct 22, 2012 2:14 pm
Posts: 51
Post Re: What is a 4-stage ultrasonic movement command?
so if i want it to stop, turn, and move forward i would put them within those 3 brackets?
....and you have any more advice for me on this topic?


Wed Oct 24, 2012 6:34 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: What is a 4-stage ultrasonic movement command?
Yes, basically, on every loop, you check the sonar sensor and other sensors to decide what to do. For example, if the sonar sensor sensed no obstacles within 25 cm, then go straight ahead, then the code would look like this:
Code:
task main()
{
    while (true)
    {
        if (SensorValue[sonarSensor] > distance_in_cm)
        {
            // move straight forward.
            motor[motorD] = 30;
            motor[motorE] = 30;
        }
        else if (some_other_condition)
        {
            // turn.
            motor[motorD] = 0;
            motor[motorE] = 50;
        }
        else
        {
            // stop the motors.
            motor[motorD] = 0;
            motor[motorE] = 0;
        }
        wait1Msec(100);
    }
}


Wed Oct 24, 2012 6:41 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: What is a 4-stage ultrasonic movement command?
This code will make the robot go forward until it's x distance from the wall, stop, turn, and move forward until it's y distance from the wall (based on the code you provided):
Code:
task main(){
  while(SensorValue[sonarSensor] > x){
    motor[motorD] = 30;
    motor[motorE] = 30;
  }

  motor[motorD] = 0;
  motor[motorE] = 0;

  motor[motorD] = 0;
  motor[motorE] = 50;
  wait1Msec(1000);

  while(SensorValue[sonarSensor] > y){
    motor[motorD] = 30;
    motor[motorE] = 30;
  }

  motor[motorD] = 0;
  motor[motorE] = 0;
}

_________________
sudo rm -rf /


Last bumped by royalthemaster on Tue Nov 20, 2012 4:53 pm.


Tue Nov 20, 2012 4:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 14 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.