View unanswered posts | View active topics It is currently Wed Jul 30, 2014 4:22 am






Reply to topic  [ 5 posts ] 
RCX "Square-Root" function 
Author Message
Rookie
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 38
Location: Tasmania, the Land Down Under, the Land Downunder!
Post RCX "Square-Root" function
Hi,

I'm using RobotC 2.03 (7 .98), Feb 1 2012.

I'm unable to get the "Square Root" function to work. When I attempt to compile the program I receive: **Error**:Undefined procedure 'sqrt'.

Can someone point out what I'm doing wrong please?

Code:
#pragma config(Sensor, S1,     touchSensor1,        sensorTouch)
#pragma config(Sensor, S2,     touchSensor2,        sensorTouch)
#pragma config(Sensor, S3,     touchSensor3,        sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
Original Code by Ray McNamara (www.rjmcnamara.com)

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version. In particular, you must
report the name of the original author.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.qrt
See the GNU General Public License for more details.

You can get a copy of the GNU General Public License from www.gnu.org.

*/


/**********************************************************************************
*              Set Constants and Variables                                        *
**********************************************************************************/

float  V1, V2, V3;
int    Vx, Vy, PowerA, PowerB, PowerC, oldVx, oldVy;


/**********************************************************************************
*              Change Robots Direction of travel                             *
***********************************************************************************/
void ChangeDirection()
{
  Vx = random(200)-100;                 // Object Found, Change Vx Direction
  Vy = random(200)-100;                 // Object Found, Change Vy Direction
  if (Vx < 30 && Vx > -30 && Vy < 30 && Vy > -30)
  { Vx = 30;
    Vx = -30;
  }             // Set Minimum Vx Direction
}




/**********************************************************************************
*              Monitor the 3x Utrasonic Sonar Sensors                             *
***********************************************************************************/
task MonitorSensors()
{
  while (true)
  {

    // Sonar 1
    if (SensorValue(touchSensor1) == 1 && SensorValue(touchSensor2) == 0 && SensorValue(touchSensor3) == 0)
    {
      Vx = 100;                   // Object Found, Change Vy Direction
      Vy = 0;                      // Object Found, Change Vy Direction

    }

    // Sonar 2
    if (SensorValue(touchSensor1) == 0 && SensorValue(touchSensor2) == 1 && SensorValue(touchSensor3) == 0)
    {
      Vx = 0;                      // Object Found, Change Vy Direction
      Vy = 100;                    // Object Found, Change Vy Direction

    }

    // Sonar 3
    if (SensorValue(touchSensor1) == 0 && SensorValue(touchSensor2) == 0 && SensorValue(touchSensor3) == 1)
    {
      Vx = 0;                      // Object Found, Change Vy Direction
      Vy = -100;                // Object Found, Change Vy Direction

    }


    // Sonar 1 & 2
    if (SensorValue(touchSensor1) == 1 && SensorValue(touchSensor2) == 1 && SensorValue(touchSensor3) == 0)
    {
      Vx = 100;                 // Object Found, Change Vy Direction
      Vy = 100;                 // Object Found, Change Vy Direction

    }


    // Sonar 2 & 3
    if (SensorValue(touchSensor1) == 0 && SensorValue(touchSensor2) == 1 && SensorValue(touchSensor3) == 1)
    {
      Vx = -100;                // Object Found, Change Vy Direction
      Vy = 0;                 // Object Found, Change Vy Direction

    }


    // Sonar 3 & 1
    if (SensorValue(touchSensor1) == 1 && SensorValue(touchSensor2) == 0 && SensorValue(touchSensor3) == 1)
    {
      Vx = -100;                 // Object Found, Change Vy Direction
      Vy = -100;                               // Object Found, Change Vy Direction

    }
    wait1Msec(50);
  }
}



/**********************************************************************************
*              Main Killough Platform Control                                     *
***********************************************************************************/
task main()
{

  StartTask(MonitorSensors);                     // Start Monitoring the Ultrasonic Sonar Sensors

  ChangeDirection();

  while (true)
  {
    int count = 0;
    oldVx = Vx; oldVy = Vy;

    V1 = Vx;                                // Vector Calculation for MotorA(V1)'s Power

    V2 = -Vx/2 - sqrt(3)/2 * Vy;        // Vector Calculation for MotorB(V2)'s Power

    V3 = -Vx/2 + sqrt(3)/2 * Vy;        // Vector Calculation for MotorC(V3)'s Power

    PowerA = V2;                            // Convert to an Integer Value for MotorA
    PowerB = V1;                            // Convert to an Integer Value for MotorB
    PowerC = V3;                            // Convert to an Integer Value for MotorC

    motor[motorA] = PowerA;                 // Set MotorA's Velocity (Power Setting)
    motor[motorB] = PowerB;                 // Set MotorB's Velocity (Power Setting)
    motor[motorC] = PowerC;                 // Set MotorC's Velocity (Power Setting)

    while (oldVx == Vx && oldVy == Vy)
    {
      wait1Msec(50);
      count = count + 1;
      if (count == 50) {ChangeDirection(); count = 0;}
    }
  }
}


I can't even get the example code from the help file to compile:
Code:
task main()
{
  float result = sqrt(1764);
}


I trust someone is able to point me in the right direction.


Attachments:
Holonomic.C [5.24 KiB]
Downloaded 208 times

_________________
regards

Sparra Mc


Image
Fri Apr 19, 2013 10:44 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: RCX "Square-Root" function
Hmm, my bet is that this is a remnant of the conversion from the RCX & NXT RobotC 2.02 to the RCX only 2.03. I'm thinking it doesn't include the function. If that's the case, you'll need to recreate it.

_________________
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.


Fri Apr 19, 2013 10:48 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: RCX "Square-Root" function
I don't think the RCX has float support, does it?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 19, 2013 11:06 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: RCX "Square-Root" function
No, I seem to recall using floats with it before. I could be wrong though.

_________________
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.


Fri Apr 19, 2013 11:24 am
Profile WWW
Rookie
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 38
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Re: RCX "Square-Root" function
According to RCX Help File RobotC does. Yet NXC doesn't.

_________________
regards

Sparra Mc


Image


Fri Apr 19, 2013 5:35 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.