View unanswered posts | View active topics It is currently Fri Oct 31, 2014 4:24 am






Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Teleop Code With Magnet? Help! 
Author Message
Rookie

Joined: Tue Oct 19, 2010 1:16 am
Posts: 9
Post Re: Teleop Code With Magnet? Help!
Ok, is there something wrong in my code then. When Im running it, I am able to see the numbers rolling that the magnetic sensor is working, but it wont move it during autonomous.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Sensor, S2,     HTMAG,               sensorHiTechnicMagnetic)
#pragma config(Sensor, S3,     ,                    sensorLightActive)
#pragma config(Motor,  motorA,          motorA,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    Sorter,               tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_5,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_6,    ,                     tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


void initializeRobot()
{
servo[Sorter]= 0;

  return;
}

void processMagnet()
{
    if(SensorValue[HTMAG] > 670)
    {
        servo[Sorter] = 127;
    }
    else if(SensorValue[HTMAG] < 665)
    {
        servo[Sorter] = 255;
    }
    else
    {
        servo[Sorter] = 0;
    }
}

task main()
{
  initializeRobot();

  waitForStart();   // wait for start of tele-op phase

  while (true)
  {

    motor[motorD] = joystick.joy1_y1;//Driving Base Right
    motor[motorE] = joystick.joy1_y2;//Driving Base Left
    motor[motorG] = joystick.joy2_y1;// Arm

   if(joy1Btn(8))//Baton Wheel 1st
   {
    motor[motorA] = 75;
   }
   else if(joy1Btn(7))//Baton Wheel 2nd
   {
     motor[motorA] = -75;
   }
   else
   {
     motor[motorA] = 0;
   }
   if(joy1Btn(1))//Bucket Level, Angle 1 Shake
    {
      servoTarget[servo4] = 78;
      servoTarget[servo5] = 160;
    }
   else if (joy2Btn(1))//Bucket Level, Angle 1
    {
      servoTarget[servo4] = 68;
      servoTarget[servo5] = 170;
    }
   else if (joy2Btn(2))//Bucket Level, Angle 2
    {
      servoTarget[servo4] = 101;
      servoTarget[servo5] = 143;
    }
   else if (joy1Btn(3))//Bucket Level, Angle 3 Shake
    {
      servoTarget[servo4] = 127;
      servoTarget[servo5] = 114;
    }
   else if (joy2Btn(3))//Bucket Level, Angle 3
    {
      servoTarget[servo4] = 117;
      servoTarget[servo5] = 124;
    }
   else if(joy2Btn(6))//Bucket Twist Right Goal
    {
      servoTarget[servo4] = 61;
      servoTarget[servo5] = 155;
      servoTarget[servo6] = 76;
    }
   else if (joy2Btn(5))//Bucket Twist Left Goal
    {
      servoTarget[servo4] = 82;
      servoTarget[servo5] = 174;
      servoTarget[servo6] = 155;
   }
   else if (joy2Btn(8))//Bucket Twist Back Goal
    {
    servoTarget[servo6] = 20;
   }
   else
    {
      servoTarget[servo4] = 105;
      servoTarget[servo5] = 137;
      servoTarget[servo6] = 129;
 }
   if (joy1Btn(4))//Flap
    {
    servoTarget[servo3] = 134;
   }
   else
   {
     servoTarget[servo3] = 14;
   }
   if (joy1Btn(5))//Trailer
    {
    servoTarget[servo2] = 143;
   }
   else if (joy1Btn(6))
    {
    servoTarget[servo2] = 163;
   }
   else
   {
     servoTarget[servo2] = 100;
   }
}
}


Thanks


Fri Mar 04, 2011 9:52 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Teleop Code With Magnet? Help!
There are a lot of limitations using RobotC tasks. For example, you cannot call the same function from two different tasks. I found I can almost always do without tasks. We did our own coooperative multi-tasking within a single task.


Fri Mar 04, 2011 1:51 pm
Profile
Rookie

Joined: Tue Oct 19, 2010 1:16 am
Posts: 9
Post Re: Teleop Code With Magnet? Help!
Ok, Im sorry, im still new to all this programming, but I have come a ways. When you say that I have mutiple tasks for the same thing, where is that in my code, could you show me?


Fri Mar 04, 2011 6:43 pm
Profile
Rookie

Joined: Tue Oct 19, 2010 1:16 am
Posts: 9
Post Re: Teleop Code With Magnet? Help!
Nevermind, thank you for your help... I got the sensor to work.


Fri Mar 04, 2011 8:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page Previous  1, 2

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.