Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: HiTechnic Magnetic Sensor (http://www.chiefdelphi.com/forums/showthread.php?t=98454)

MonikkaM 26-11-2011 02:41

[FTC]: HiTechnic Magnetic Sensor
 
Hello Again!

Back trying to help out my teen with her robot.

Are there some additional programming resources showing the use of the magnetic sensor with RobotC?

Essentially, she downloaded the drivers from Xander's website, installed them in RobotC and tried running the sample codes. She's confused and since my background is in Material Science (& Dad is a physicist); programming is not our thing.

After about 5 hours of struggling through it on her own and searching high & low online, she still is saying that she's not clear on a) how the sensor is addressed by the program, b) how to use whatever data is being gathered by the sensor, c) whether or not she installed it properly and d) can/how does she hook up a light bulb to tell her if the ball is magnetic or not?

The rest of her team took the holiday off and were supposed to come over to our house (her coach let her bring the robot & parts home since he was not going to be at school) and only one teammate showed up (and he is more involved in the mechanical). I'm so proud of her for stepping up to the plate and trying to do 110% (their first regional is on 12/4) but I think she might have bitten off more than she can chew!

Team 2844 26-11-2011 10:19

Re: [FTC]: HiTechnic Magnetic Sensor
 
Code:

#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTServo)
#pragma config(Sensor, S1,    ,                    sensorI2CMuxController)
#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,  motorC,          motorC,        tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C1_1,    motorRight,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,    motorLeft,    tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,    motorL,    tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,    motorF,    tmotorNormal, openLoop, reversed)
#pragma config(Servo,  srvo_S1_C3_1,    Mag1,                tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    lift2,                tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    leftflap3,            tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    rightflap4,          tServoStandard)
#pragma config(Servo,  srvo_S1_C3_5,    MagR5,                tServoStandard)
#pragma config(Servo,  srvo_S1_C3_6,    MagG,                tServoStandard)
#pragma config(Servo,  srvo_S1_C4_1,    fL7,              tServoStandard)
#pragma config(Servo,  srvo_S1_C4_2,    fR8,              tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//

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

bool btn2Pressed = false;
bool MagnetReleaseIsUp = false;

void initializeRobot()
{
  servoTarget[Mag1] = 127;
  servoTarget[lift2] = 0;
  servoTarget[leftflap3] = 23;
  servoTarget[rightflap4] = 112;
  servoTarget[fL7] = 0;
  servoTarget[fR8] = 0;
  servoTarget[MagR5] = 0;

  return;
}

void processMagnet()
{
    if(SensorValue[HTMAG] > 670) // Magnetic Ball
    {
      servoTarget[Mag1] = 230;
      wait1Msec(1000);
    }
    else if(SensorValue[HTMAG] < 660)// Magnetic Ball
    {
      servoTarget[Mag1] = 230;
      wait1Msec(1000);
    }
    else
    {
      servoTarget[Mag1] = 127;
    }
}

task main()
{
  initializeRobot();

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

  while (true)
  {

    getJoystickSettings(joystick);
    processMagnet();
    motor[motorLeft] = joystick.joy1_y1;
    motor[motorRight] = joystick.joy1_y2;

In our case, we sort the magnetic ball by a servo. What we did was tap into the servo wires, negative and positive, and attached a LED to that. On our old robot we only determined the magnetic ball by a LED that was hooked into the motor port, really just acting like a motor turning off and on.

Up above you can see the beginning of our teleopcode, you need to have the void magnet before the while true like we have above. put the processMagnet in the while true like we have above too.

I know how you feel, it took me and another team forever last year to find out this.

Hope this helps.

kz2zx 27-11-2011 01:04

Re: [FTC]: HiTechnic Magnetic Sensor
 
Quote:

Originally Posted by MonikkaM (Post 1086707)
she's not clear on a) how the sensor is addressed by the program

It's in the #pragma the sensors/servos configuration dialog box puts in for you.

In the example code Team_2488 put in for you above, it's this statement:

#pragma config(Sensor, S2, HTMAG, sensorHiTechnicMagnetic)


Quote:


b) how to use whatever data is being gathered by the sensor, c) whether or not she installed it properly and d) can/how does she hook up a light bulb to tell her if the ball is magnetic or not?
For b), Team_2488's code will indeed work; we used a magnetic reed switch and had to debounce it :(.

For c), hook up an LED... and try waving a ball in front of the sensor.

For d), Team_2488 is telling you to splice the LED in the servo wires. Do you have a HiTechnic Prototype Board in your robot? If so, you can use a B0-B5 output for your LED (put a statement in the if branches that throw the servo to turn the light on and leave it on).

Otherwise, you'll only know you have a magnet ball if you happen to be looking at the LED while the servo is moving. Since the code they've shown is blocking (meaning 'doesn't return to the event/main loop until done'), and they have a 1s timeout, you'll both need to have your servo throw done and no time to really tell if the light is on... and that doesn't help at all if you are looking for the LED to tell the human operator to activate the servo.

If you're leaving the decision to throw the servo to the NXT controller software, then you can indicate you have a magnet ball after the fact by putting a switch in the magnet ball repository (a roller momentary-contact switch works well), and use that to close a circuit to light the LED.


All times are GMT -5. The time now is 19:03.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi