View unanswered posts | View active topics It is currently Tue Oct 21, 2014 2:04 am






Reply to topic  [ 4 posts ] 
FTC Teleop program - Magnetic Sensor with Sensor Multiplexor 
Author Message
Rookie

Joined: Wed Feb 22, 2012 4:23 am
Posts: 10
Post FTC Teleop program - Magnetic Sensor with Sensor Multiplexor
We need help getting the magnetic sensor to work with sensor multiplexor in our FTC Teleop program. We want it to move a flag on Servo 2 if the magnetic sensor detects a change, but we can't get it to calibrate the sensor's bias. Here is the relevant part of the code.

Thanks,
Ming


Code:
#pragma config(Hubs,  S1, HTServo,  HTServo,  HTMotor,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C3_1,     motorD,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C3_2,     motorE,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     motorF,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_2,     motorG,        tmotorNone, openLoop)
#pragma config(Servo,  srvo_S1_C1_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_2,    servo2,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_1,    servo7,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo8,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo9,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_4,    servo10,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_5,    servo11,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_6,    servo12,              tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "drivers/HTSMUX-driver.h"
#include "drivers/HTMAG-driver.h"

const tMUXSensor HTMAG = msensor_S2_4;

void initializeRobot()
{
  //from the front of the robot
  servo[servo1] = 138; //right bowling ball servo up pos
  servo[servo12] = 96; //left bowling ball servo up pos

  servo[servo7] = 0; //from the front, the left hand servo is a 0 when the arm is extended. It is at 229 when it is at its lowest.
  servo[servo8] = 0; //from the front, the right hand servo is a 26 when the arm is extended. It is at 255 when it is at its lowest.

  servo[servo9] = 225; //small servo joint
  servo[servo2] = 0;
  return;
}

task main()
{
  initializeRobot();

  waitForStart();

  int Joint1ServoRightPos = 0;
  int Joint1ServoLeftPos = 0;
  int Joint2Pos = 225; //open pos

  while (true)
  {
    int bias = HTMAGreadCal(HTMAG);
    wait1Msec(100);
    getJoystickSettings(joystick);
    if(abs(bias - HTMAGreadCal(HTMAG))>10){
      servo[servo2] = 200;
    }
    else{
      servo[servo2] = 0;
    }


Wed Feb 22, 2012 4:48 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: FTC Teleop program - Magnetic Sensor with Sensor Multipl
Your program wasn't complete (it was cut off at the bottom) but here is something that at least compiles:
Code:
#pragma config(Hubs,  S1, HTServo,  HTServo,  HTMotor,  HTMotor)
#pragma config(Sensor, S2,     HTSMUX,         sensorI2CCustom)
#pragma config(Motor,  mtr_S1_C3_1,     motorD,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C3_2,     motorE,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     motorF,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_2,     motorG,        tmotorNone, openLoop)
#pragma config(Servo,  srvo_S1_C1_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_2,    servo2,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_1,    servo7,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo8,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo9,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_4,    servo10,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_5,    servo11,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_6,    servo12,              tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "drivers/HTSMUX-driver.h"
#include "drivers/HTMAG-driver.h"

const tMUXSensor HTMAG = msensor_S2_4;

void initializeRobot()
{
  // calibrate the Magnetic sensor
  HTMAGstartCal(HTMAG);
 
  //from the front of the robot
  servo[servo1] = 138; //right bowling ball servo up pos
  servo[servo12] = 96; //left bowling ball servo up pos

  servo[servo7] = 0; //from the front, the left hand servo is a 0 when the arm is extended. It is at 229 when it is at its lowest.
  servo[servo8] = 0; //from the front, the right hand servo is a 26 when the arm is extended. It is at 255 when it is at its lowest.

  servo[servo9] = 225; //small servo joint
  servo[servo2] = 0;
  return;
}

task main()
{
  initializeRobot();

  waitForStart();

  int Joint1ServoRightPos = 0;
  int Joint1ServoLeftPos = 0;
  int Joint2Pos = 225; //open pos

  while (true)
  {
    getJoystickSettings(joystick);
    if(abs(HTMAGreadVal(HTMAG))>10){
      servo[servo2] = 200;
    }
    else{
      servo[servo2] = 0;
    }
  }
}


Your Sensor MUX is attached to S2, that means you need to configure that sensor port as an I2C sensor, like in the example program HTMAG-SMUX-test1.c. I have added the proper pragma to your program so you can see.
Additionally, you need to calibrate your sensor at the start of your program, so I have added that to your initialisation function. After that you don't need to look at the bias again. To get the calibrated value from the sensor, just read it with HTMAGreadVal();

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 22, 2012 5:07 am
Profile WWW
Rookie

Joined: Wed Feb 22, 2012 4:23 am
Posts: 10
Post Re: FTC Teleop program - Magnetic Sensor with Sensor Multipl
OK, thanks! I did that but it's still not moving the servo when I put a magnetic in front of the sensor. Also, I think it's doing something odd - it seems to be starting and stopping repeatedly. Thanks.

Ming

[code][/code]#pragma config(Hubs, S1, HTServo, HTServo, HTMotor, HTMotor)
#pragma config(Sensor, S2,HTSMUX, sensorI2CCustom)
#pragma config(Motor, mtr_S1_C3_1, motorD, tmotorNormal, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_2, motorE, tmotorNormal, openLoop, encoder)
#pragma config(Motor, mtr_S1_C4_1, motorF, tmotorNormal, openLoop, encoder)
#pragma config(Motor, mtr_S1_C4_2, motorG, tmotorNone, openLoop)
#pragma config(Servo, srvo_S1_C1_1, servo1, tServoStandard)
#pragma config(Servo, srvo_S1_C1_2, servo2, tServoStandard)
#pragma config(Servo, srvo_S1_C1_3, servo3, tServoStandard)
#pragma config(Servo, srvo_S1_C1_4, servo4, tServoStandard)
#pragma config(Servo, srvo_S1_C1_5, servo5, tServoStandard)
#pragma config(Servo, srvo_S1_C1_6, servo6, tServoStandard)
#pragma config(Servo, srvo_S1_C2_1, servo7, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, servo8, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, servo9, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, servo10, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, servo11, tServoStandard)
#pragma config(Servo, srvo_S1_C2_6, servo12, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"
#include "drivers/HTSMUX-driver.h"
#include "drivers/HTMAG-driver.h"

const tMUXSensor HTMAG = msensor_S2_4;

void initializeRobot()
{
// calibrate the Magnetic sensor
HTMAGstartCal(HTMAG);

//from the front of the robot
servo[servo1] = 138; //right bowling ball servo up pos
servo[servo12] = 96; //left bowling ball servo up pos

servo[servo7] = 0; //from the front, the left hand servo is a 0 when the arm is extended. It is at 229 when it is at its lowest.
servo[servo8] = 0; //from the front, the right hand servo is a 26 when the arm is extended. It is at 255 when it is at its lowest.

servo[servo9] = 225; //small servo joint
servo[servo2] = 0;
return;
}

task main()
{
initializeRobot();

waitForStart();

int Joint1ServoRightPos = 0;
int Joint1ServoLeftPos = 0;
int Joint2Pos = 225; //open pos

while (true)
{
wait1Msec(100);
getJoystickSettings(joystick);
if(abs((HTMAGreadVal(HTMAG))>10){
servo[servo2] = 200;
}
else{
servo[servo2] = 0;
}

//The following code programs which motors should be controlled by the joysticks
//motor is the left hand motor and motor is the right hand motor
motor[motorE] = -joystick.joy1_y1;
motor[motorD] = joystick.joy1_y2;

//servo 1 is the right hand bowling ball servo (from the front of the robot)
//servo 12 is the left hand bowling ball servo (from the front of the robot)
if(joy1Btn(1) == 1)
{
servo[servo1] = 138;
servo[servo12] = 96;
//up
}

if(joy1Btn(2) == 1)
{
servo[servo1] = 5;
servo[servo12] = 240;
//down
}

//The following code programs the smaller, 2nd joint of the arm
if(joy2Btn(5) == 1)
{
Joint2Pos = Joint2Pos+1;
wait1Msec(5);
//close
}

if(joy2Btn(6) == 1)
{
Joint2Pos = Joint2Pos-1;
wait1Msec(5);
//open
}

servo[servo9] = Joint2Pos;


//The following code programs the larger, 1st joint of the arm
if(joy2Btn(8) == 1)
{
Joint1ServoLeftPos = Joint1ServoLeftPos+1;
Joint1ServoRightPos = Joint1ServoRightPos+1;
wait1Msec(5);
//open
}

if(joy2Btn(7) == 1)
{
Joint1ServoLeftPos = Joint1ServoLeftPos-1;
Joint1ServoRightPos = Joint1ServoRightPos-1;
wait1Msec(5);
//close
}

servo[servo7] = Joint1ServoLeftPos;
servo[servo8] = Joint1ServoRightPos;

//The following code programs the DC motor at the base
motor[motorF] = -(1/2.56)*joystick.joy2_y2;

}
}


Wed Feb 22, 2012 6:46 am
Profile
Rookie

Joined: Wed Feb 22, 2012 4:23 am
Posts: 10
Post Re: FTC Teleop program - Magnetic Sensor with Sensor Multipl
Not sure what happened, but it's working now. Thanks, Ming


Wed Feb 22, 2012 8:14 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.