ROBOTC.net forums
http://www.robotc.net/forums/

RobotC 2.3 Help
http://www.robotc.net/forums/viewtopic.php?f=53&t=2978
Page 1 of 1

Author:  Dracco1993 [ Tue Feb 01, 2011 11:44 pm ]
Post subject:  RobotC 2.3 Help

Hello,

I have just regestered the new version (2.3) of RobotC on my computer. I have loaded all the new firmware onto my cortex and both of my controlers. I am working with a cortex controler and am trying to get some line sensors to work. I started with the sample line following program and that didn't work so I added some code to display three variables that are the inputs of the three line sensors that I have. I was able to run the program (and other programs that I had made before) but I was surprised to find out that the variables that I added did not change when I moved the robot around over different lines. After a little messing around I saw that the variables always displayed the same numbers, so I moved what port they were in. What I found surprised me. They were not the same numbers but they always displayed the number of port they were in minus one. (For example: line sensor in port one read 0, sensor in port 2 read 1, and so on...) So right now I am not able to use any of my analog inputs. I have tryed and all of the digital inputs work fine. Here is the code that I am trying to use.

Code:
#pragma config(Sensor, in1,    lineFollowerRIGHT,   sensorLineFollower)
#pragma config(Sensor, in2,    lineFollowerCENTER,  sensorLineFollower)
#pragma config(Sensor, in3,    lineFollowerLEFT,    sensorLineFollower)
#pragma config(Motor,  port1,           rightMotor,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port10,          leftMotor,     tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{

  int threshold = 5;      /* found by taking a reading on both DARK and LIGHT    */
                          /* surfaces, adding them together, then dividing by 2. */

  int left;
  int right;
  int center;

  while(true)
  {
    left = lineFollowerLEFT;
    right = lineFollowerRIGHT;
    center = lineFollowerCENTER;


    // RIGHT sensor sees dark:
    if(SensorValue(lineFollowerRIGHT) > threshold)
    {
      // counter-steer right:
      motor[leftMotor]  = 100;
      motor[rightMotor] = -100;
    }
    // CENTER sensor sees dark:
    if(SensorValue(lineFollowerCENTER) > threshold)
    {
      // go straight
      motor[leftMotor]  = 100;
      motor[rightMotor] = 100;
    }
    // LEFT sensor sees dark:
    if(SensorValue(lineFollowerLEFT) > threshold)
    {
      // counter-steer left:
      motor[leftMotor]  = -100;
      motor[rightMotor] = 100;
    }
  }
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Author:  mightor [ Wed Feb 02, 2011 2:45 am ]
Post subject:  Re: RobotC 2.3 Help

When you create a pragma section like this:
Code:
#pragma config(Sensor, in1,    lineFollowerRIGHT,   sensorLineFollower)
#pragma config(Sensor, in2,    lineFollowerCENTER,  sensorLineFollower)
#pragma config(Sensor, in3,    lineFollowerLEFT,    sensorLineFollower)
#pragma config(Motor,  port1,           rightMotor,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port10,          leftMotor,     tmotorNormal, openLoop)


You are setting up aliases for the in1, in2 and in3 sensor ports. Those sensor ports are indicated with a number, like this (from RobotCIntrinsics.c):
Code:
typedef enum
{
  //
  // Analog I/O Ports: light, line follower, gyro, accelerometer,
  //
  in1    =  0,
  in2    =  1,
  in3    =  2,
  in4    =  3,
  in5    =  4,
  in6    =  5,
  in7    =  6,
  in8    =  7,

  //
  // Digital I/O Ports: Touch sensors, sonar, etc
  //
  dgtl1  = 8,
  dgtl2  = 9,
  dgtl3  = 10,
  dgtl4  = 11,
  dgtl5  = 12,
  dgtl6  = 13,
  dgtl7  = 14,
  dgtl8  = 15,
  dgtl9  = 16,
  dgtl10 = 17,
  dgtl11 = 18,
  dgtl12 = 19,
  dgtl13 = 20,

} tSensors;


So when you do something like:
Code:
int left = lineFollowerLEFT;


What you are really doing is this:
Code:
left = in3;


and in3 is really just a single constant number, 2.

If you were looking to assign the value of the sensor attached to in3, you should do this:
Code:
int left = SensorValue(lineFollowerLEFT);


Regards,
Xander

Author:  Dracco1993 [ Wed Feb 02, 2011 10:28 am ]
Post subject:  Re: RobotC 2.3 Help

=D Haha Thank you for your help. I have used SensorValue before, but it was late last night so I guess I forgot about that part. =P Thanks for explaining what I did and what was actualy going on. Everything seems to be working now.

Thanks again,
Jordan

Author:  mightor [ Wed Feb 02, 2011 10:32 am ]
Post subject:  Re: RobotC 2.3 Help

Glad to hear it :)

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/