OCCRA
Go to Post The spirit of FIRST lives in all of them[us]. Knowledge is power and the unknown is scarey but in the end the spirit of FIRST will endure. - LSevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-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 06-16-2008, 05:27 PM
DanielR. DanielR. is offline
Registered User
no team
 
Join Date: Apr 2008
Location: SELU
Posts: 6
DanielR. is an unknown quantity at this point
WPILib and Ultrasonic sensors

Ok, I have an easy one.

I am trying to get ultrasonic sensors to work on a Vex using WPILib.

This is my code:
Code:
#define _VEX_BOARD
#include "API.h"
#include "BuiltIns.h"

#define UltraOnePing	1
#define UltraOneEcho	1

int sonicValue;

void main(void){

StartUltrasonic(UltraOneEcho, UltraOnePing);
PrintToScreen("Start");
	while(1==1)
           {
		sonicValue = GetUltrasonic(UltraOneEcho, UltraOnePing);
		PrintToScreen("Ultra returns %d. \n", sonicValue);
	
	   }
}
I get nothing. I have tried also with RobotC and had success, so I know the sensor works. I cannot figure out what is wrong.

Do I need to set port direction (tried that, didn't work, maybe I did it wrong)?

Does it have something to do with DefineControllerIO()?

Is it a conspiracy? I just don't know.

Last edited by DanielR. : 06-17-2008 at 11:59 AM.
Reply With Quote
  #2   Spotlight this post!  
Unread 06-16-2008, 05:39 PM
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins Send a message via Skype™ to EHaskins
Re: WPILib and Ultrasonic sensors

Assuming you're using the Vex Ultrasonic sensor, then the input(echo, sensor output) and output(ping, sensor input) ports should be different.

If you're using non-vex sensors you may need to use the analog input, and bypass the wpilib functions.
__________________
Eric Haskins KC9JVH
Reply With Quote
  #3   Spotlight this post!  
Unread 06-16-2008, 05:51 PM
DanielR. DanielR. is offline
Registered User
no team
 
Join Date: Apr 2008
Location: SELU
Posts: 6
DanielR. is an unknown quantity at this point
Re: WPILib and Ultrasonic sensors

Thank you for the response. Using vex sensors. The echo is on (interrupt port 1), and the ping is on (analog/digital port 1). Also, I have tried it with echo=1 and ping = 1 -11.

The current configuration is the one that worked in RobotC. I have not changed the sensor's wiring.
Reply With Quote
  #4   Spotlight this post!  
Unread 06-16-2008, 09:42 PM
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins Send a message via Skype™ to EHaskins
Re: WPILib and Ultrasonic sensors

Quote:
Originally Posted by DanielR. View Post
Thank you for the response. Using vex sensors. The echo is on (interrupt port 1), and the ping is on (analog/digital port 1). Also, I have tried it with echo=1 and ping = 1 -11.

The current configuration is the one that worked in RobotC. I have not changed the sensor's wiring.
I forgot the Vex has the interupts and the digital I/O pins seperated.

I don't see any obvious problems with the code. Hopefully someone who has more experiance with WPILib/RobotC can answer your question.
__________________
Eric Haskins KC9JVH
Reply With Quote
  #5   Spotlight this post!  
Unread 06-18-2008, 07:58 AM
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 858
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: WPILib and Ultrasonic sensors

By default
Ports 1-4 Are Assigned to Analog Inputs
Ports 5-10 Are Assigned Digital Inputs
Ports 11-16 Are Assigned Digital Ouputs

So you either need to re-assign that port (see documentation) or move the
pulse port to I/O Port 11 or higher.
__________________
Intelitek Support

[BFIRST Team 146 Blue Lightning - Alumni[/b]
FIRST Team 40 Checkmate
Reply With Quote
  #6   Spotlight this post!  
Unread 06-18-2008, 02:27 PM
DanielR. DanielR. is offline
Registered User
no team
 
Join Date: Apr 2008
Location: SELU
Posts: 6
DanielR. is an unknown quantity at this point
Re: WPILib and Ultrasonic sensors

Quote:
Originally Posted by Kingofl337 View Post
By default
Ports 1-4 Are Assigned to Analog Inputs
Ports 5-10 Are Assigned Digital Inputs
Ports 11-16 Are Assigned Digital Ouputs

So you either need to re-assign that port (see documentation) or move the
pulse port to I/O Port 11 or higher.
{ The following is the post I was in the process of writing when I had an idea I felt the need to verify. }
Thanks, I guess I didn't see that in the documentation. However, I did try moving the input connection to Digital Output 11 and 16, with no change in results.

Well, not exactly . . . once when I turned the Vex back on to upload a code modification it started outputting the Ultrasonic value to the terminal. It did it really fast as well, instead of the slow crawl it does when it is not working.

I really wish I knew what was going on here.
{End post}

Umm, what ... I am now confused and mystified.

It works now. Sort of. Here is what happened...
1) changed #define UltraOnePing from '1' to '11'
2) moved 'input' from port 1 to port 11
3) uploaded code
4) nuthin'
...
5) changed #define UltraPingOne from '11' to '16'
6) moved 'input' from port 11 to port 16
7) uploaded code -->terminal popped up while uploading and Vex was outputting expected values, upload completed, no more good output.
8) Wrote response on CD...had a thought.
9)changed #define UltraPingOne back to '11'
10) left 'input' plugged into port 16
11) uploaded code
12) Now it works.

If I set the Ping port to 11 and plug the wire into port 16 it works. The echo (output) wire is still plugged in to interrupt port 1.

I have nothing more to say about that.
Reply With Quote
  #7   Spotlight this post!  
Unread 06-18-2008, 03:44 PM
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 858
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: WPILib and Ultrasonic sensors

Try this.
Code:
#define _VEX_BOARD
#include "API.h"
#include "BuiltIns.h"

#define UltraOnePing	11
#define UltraOneEcho	1

int sonicValue;

void main(void){

DefineControllerIO ( 4, 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ) ;

StartUltrasonic(UltraOneEcho, UltraOnePing);
PrintToScreen("Start");
	while(1==1)
           {
		sonicValue = GetUltrasonic(UltraOneEcho, UltraOnePing);
                Wait(1);
		PrintToScreen("Ultra returns %d. \n", sonicValue);
	
	   }
}

DefineControllerIO ( 4, 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ) ;
4 = Number Of Analog Ports //First ports are always analog
1 = Input
0 = Output
__________________
Intelitek Support

[BFIRST Team 146 Blue Lightning - Alumni[/b]
FIRST Team 40 Checkmate

Last edited by Kingofl337 : 06-18-2008 at 03:47 PM.
Reply With Quote
  #8   Spotlight this post!  
Unread 06-18-2008, 04:31 PM
DanielR. DanielR. is offline
Registered User
no team
 
Join Date: Apr 2008
Location: SELU
Posts: 6
DanielR. is an unknown quantity at this point
Re: WPILib and Ultrasonic sensors

Thanks again. I still am reading off of port 16 when port 11 is what is in the code. Also, it seems that is the only configuration I can find that works.

It is odd.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallax and Maxbotix ultrasonic sensors Lucretius Programming 5 02-20-2008 01:34 PM
Ultrasonic sensors on digital ports 3-6 problems wt200999 Programming 14 02-13-2008 07:13 AM
Ultrasonic range sensors for Vex Robot OneCoolDude Programming 1 12-01-2007 08:22 AM
can we use ultrasonic sensors? GMKlenklen Electrical 20 01-15-2007 01:34 PM
Gryo, Camera, Accelorometer, Ultrasonic, and Gear Tooth Sensors in one program EHaskins Programming 8 05-22-2006 11:08 AM


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

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


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