View unanswered posts | View active topics It is currently Wed Aug 27, 2014 9:54 pm






Reply to topic  [ 4 posts ] 
RobotC 2.3 Help 
Author Message
Rookie

Joined: Fri Sep 04, 2009 3:03 pm
Posts: 10
Post 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;
    }
  }
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

_________________
Jordan Miller
2010 Dean's List Semi-Finalist
FRC 1741 --- Engineering Captain, Driver
Vex 323a --- Team Captain, Driver


Tue Feb 01, 2011 11:44 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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

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


Wed Feb 02, 2011 2:45 am
Profile WWW
Rookie

Joined: Fri Sep 04, 2009 3:03 pm
Posts: 10
Post 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

_________________
Jordan Miller
2010 Dean's List Semi-Finalist
FRC 1741 --- Engineering Captain, Driver
Vex 323a --- Team Captain, Driver


Wed Feb 02, 2011 10:28 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: RobotC 2.3 Help
Glad to hear 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]


Wed Feb 02, 2011 10:32 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 0 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.