Go to Post I just think the teams that will be winners will have a higher score then us :) - Kyle [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2014, 18:44
jordan11623's Avatar
jordan11623 jordan11623 is offline
Registered User
FRC #4641
 
Join Date: Jan 2014
Location: United States
Posts: 5
jordan11623 is an unknown quantity at this point
Need a bit of help with the Sonar

Our model number is MB1222, we're unsure how to wire it and schemeatics aren't really helping. We'd like help so that we can use for the FIRST Robotics Competion. We've hooked up positive and negative, now we're kind of stuck. Specificaly, we don't know how to hook up the signal wire. Thanks.
-Team 4641
Reply With Quote
  #2   Spotlight this post!  
Unread 05-02-2014, 07:48
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Need a bit of help with the Sonar

You've chosen a part that requires more programming support than most. http://www.maxbotix.com/Ultrasonic_Sensors/MB1222.htm says that it connects via the I2C interface. In addition to power and ground, you'll need to wire the SDA (data) and SCL (clock) pins. What language are you using to write your robot program?
Reply With Quote
  #3   Spotlight this post!  
Unread 05-02-2014, 10:42
amesmich's Avatar
amesmich amesmich is offline
Registered User
FRC #4638 (Jagbots)
Team Role: Teacher
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Maryland
Posts: 102
amesmich is an unknown quantity at this point
Re: Need a bit of help with the Sonar

Heres some arduino code we used. We altered it greatly but it shoudl get you started.

Code:
/* This script is designed to take several readings from the maxbotix sonar and generate a mode/median.
Author: Jason Lessels
Date created: 2011/June/06
Lisence: GPL (=>2)
This work has been compileed using many sources mainly posts/wiki posts from;
Allen, Bruce (2009/July/23) and Gentles, Bill (2010/Nov/12)
*/ 


//Set the pin to recieve the signal.
const int pwPin = 7;
//variables needed to store values
int arraysize = 9; //quantity of values to find the median (sample size). Needs to be an odd number 


//declare an array to store the samples. not necessary to zero the array values here, it just makes the code clearer
int rangevalue[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
long pulse;
int modE;
 void setup() { 

  //Open up a serial connection
  Serial.begin(9600);
  //Wait for the serial connection
  delay(500);



}
//Main loop where the action takes place
void loop() { 
  pinMode(pwPin, INPUT);


  for(int i = 0; i < arraysize; i++)
  {								    


    pulse = pulseIn(pwPin, HIGH);
    rangevalue[i] = pulse/58;
    delay(10);
  }


  Serial.print("Unsorted: ");
  printArray(rangevalue,arraysize);
  isort(rangevalue,arraysize);
  Serial.print("Sorted: ");
  printArray(rangevalue,arraysize);
  modE = mode(rangevalue,arraysize);
  Serial.print("The mode/median is: ");
  Serial.print(modE);
  Serial.println();
  delay(1000);


} 


/*-----------Functions------------*/ //Function to print the arrays.
void printArray(int *a, int n) { 

  for (int i = 0; i < n; i++)
  {
    Serial.print(a[i], DEC);
    Serial.print(' ');
  }


  Serial.println();


} 


//Sorting function
// sort function (Author: Bill Gentles, Nov. 12, 2010)
void isort(int *a, int n){
// *a is an array pointer function

  for (int i = 1; i < n; ++i)
  {
    int j = a[i];
    int k;
    for (k = i - 1; (k >= 0) && (j < a[k]); k--)
    {
      a[k + 1] = a[k];
    }
    a[k + 1] = j;
  }


} 


//Mode function, returning the mode or median.
int mode(int *x,int n){ 
  int i = 0;
  int count = 0;
  int maxCount = 0;
  int mode = 0;
  int bimodal;
  int prevCount = 0;


  while(i<(n-1)){


    prevCount=count;
    count=0;


    while(x[i]==x[i+1]){


      count++;
      i++;
    }


    if(count>prevCount&count>maxCount){
      mode=x[i];
      maxCount=count;
      bimodal=0;
    }
    if(count==0){
      i++;
    }
    if(count==maxCount){//If the dataset has 2 or more modes.
      bimodal=1;
    }
    if(mode==0||bimodal==1){//Return the median if there is no mode.
      mode=x[(n/2)];
    }
    return mode;
  }


}
Reply With Quote
  #4   Spotlight this post!  
Unread 06-02-2014, 17:31
jordan11623's Avatar
jordan11623 jordan11623 is offline
Registered User
FRC #4641
 
Join Date: Jan 2014
Location: United States
Posts: 5
jordan11623 is an unknown quantity at this point
Re: Need a bit of help with the Sonar

Quote:
Originally Posted by Alan Anderson View Post
You've chosen a part that requires more programming support than most. http://www.maxbotix.com/Ultrasonic_Sensors/MB1222.htm says that it connects via the I2C interface. In addition to power and ground, you'll need to wire the SDA (data) and SCL (clock) pins. What language are you using to write your robot program?
We're writing the program in French. No, we kid. The program is Labview, I'm not really sure what the program language is... If you can help us from that point, that would be fantastic.
Reply With Quote
  #5   Spotlight this post!  
Unread 06-02-2014, 21:12
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Need a bit of help with the Sonar

Quote:
Originally Posted by jordan11623 View Post
The program is Labview, I'm not really sure what the program language is... If you can help us from that point, that would be fantastic.
Few people know that the actual name of the graphical language in the LabVIEW environment is "G". Most would just say you're programming in LabVIEW.

Why did you pick the MB1222 device? I2C is powerful, but it's one of the more complex schemes available in the MaxBotics sensor line.

If you feel up to the challenge, you can use the ADXL345 I2C Accelerometer example as a starting point. It shows how to communicate with an I2C device. The MB1222 datasheet tells what the 8-bit equivalent read and write addresses are (E0 and E1), and describes how to interpret the response.

If you aren't comfortable blazing new trails, you would find your job to be much easier if you used something like the MB1010 or MB1020 instead. Reading its output can be as simple as reading an analog voltage, something which is well supported by the FRC programming tools.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 05:28.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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