Go to Post yesterday we completed our bot mechanically and let me tell you.... i was jumping up and down like a 12 year old girl going to a boy-band concert - Leav [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 25-01-2015, 14:36
dash121 dash121 is offline
Registered User
FRC #4085
 
Join Date: Oct 2014
Location: Reynoldsburg Ohio
Posts: 23
dash121 is an unknown quantity at this point
Exclamation Two questions

I need alot of assistance!!! We spent up to 12 hours on Saturday figuring out code and staring at the same few lines fixing and fixing them and ended up at two points of needed help. One: with netbeans we could do a "System.out.println(String)" and it would appear on the console this year for (eclipse) debugging purposes we need that same type of thing. To be able to put in a variable or string and have it be able to print it as it changes any tips and where is the default system.out? 2: This year we are trying to do the same thing as last year. Last year we got an I2C sonar sensor working and able to send back distances through the I2C port. (Details on the sensor)We would like to use the same sensor again this year but the class we used last year was deleted! DANGIT FRC!
Code:
DigitalModule mod1 = DigitalModule.getIntance(1);
	I2C sensor = mod1.getI2C(0xe0); //0xe0 8 it? // 0x70 7 bit
	boolean rc=true;
	boolean rc2=true;
Code:
sensor.write(0x0,0xe0);
    	//Timer.delay(.1);
    	//give the sensor the read command
    	rc=sensor.write(0x0,0x51);
    	Timer.delay(.05); //50ms
    	//read 2 bytes from the sensor, in hi, low
    	rc2sensor.read(0x0,0x02,bytes);
    	//convert signed 8bit value in quad word int to an unsigned value
    	high = (bytes[0] << 24) >>>24;
    	low = (bytes[1] << 24) >>>24;
    	inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
But.. the DigitalModule class was deleted in the 2015 update. We started by copying the last years I2C code in a new document, found the missing class, and tried to adapt it from there.. To create the /VERY/ long new document. Can someone look at our new code and understand why our runtime error is occurring? To make this more confusing the error is at the [code]sensor3.read(0x51, 0x02, mybytes);[code] line. We know this because we got the testPeriodic code to come back as true. Again /ANY/ help is wanted!!

Code:
package org.usfirst.frc.team4085.robot;

import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.I2C.Port;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.smartdashboard.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
	/*
		DigitalModule mod1 = DigitalModule.getIntance(1);
	I2C sensor = mod1.getI2C(0xe0); //0xe0 8 it? // 0x70 7 bit
	boolean rc=true;
	boolean rc2=true;
	*/
	
	//I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection 
	//I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port 
	byte[] bytes = new byte[7];
	CANTalon dmotor1 = new CANTalon(2);
	CANTalon dmotor2 = new CANTalon(1);
	Joystick lstick = new Joystick(0);
	Joystick rstick = new Joystick(1);
	RobotDrive moving = new RobotDrive(dmotor1,dmotor2);
	SmartDashboard smart = new SmartDashboard();
	
	
	//Port port = I2C.Port.valueOf("h");
	//I2C sensor2 = new I2C(port, 0x0);
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {

    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {

    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
    	
/*
		sensor.write(0x0,0xe0);
    	//Timer.delay(.1);
    	//give the sensor the read command
    	rc=sensor.write(0x0,0x51);
    	Timer.delay(.05); //50ms
    	//read 2 bytes from the sensor, in hi, low
    	rc2sensor.read(0x0,0x02,bytes);
    	//convert signed 8bit value in quad word int to an unsigned value
    	high = (bytes[0] << 24) >>>24;
    	low = (bytes[1] << 24) >>>24;
    	inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
  */
    
    	I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection 
    	I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port 
    	
    	sensor3.write(0,0xe0);

    	boolean rc5 = sensor3.write(0, 0x0);
    	rc5 = false;
    	System.out.println("Sensor 3 Returned " + rc5);
    	System.err.println("Test Here");
    	System.out.print("System out print here");

    	Timer.delay(.05); //50ms
    	
    	//sensor2.read(0, 0x02, bytes);
    	byte[] mybytes = new byte[8];
    	int count = 1, registerAddress = 0;
    	sensor3.read(0x51, 0x02, mybytes); // need to figure out the correct values that need to be passed in. 
    	System.out.println("Test Here");
    	//sensor3.readOnly(bytes[], count);
 /*   	
    	try {
/*    	
    		sensor2.read(registerAddress, count, mybytes);
    		
  /*  		
    	} catch (java.nio.BufferUnderflowException e)
    	{
    		java.lang.Exception myexeception = new java.lang.Exception("my error message goes here");
    		
    		e.printStackTrace();
    		//throw e;
    		
    		//e.printStackTrace();
    	}
 */   	
    	
    	//int high = 0, low = 0, inches = 0;
 /*   	
    	int high = (bytes[0] << 24) >>>24;
    	int low = (bytes[1] << 24) >>>24;
    	int inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
   */ 	
    	// print out inches
    	//System.out.println("real: high: " + high + " low: " + low + "  inches: " + inches); 
    	
    	moving.tankDrive(lstick, rstick);
    	
        
    }
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    	I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection 
    	I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port 
    	byte[] mybytes = new byte[8];
    	String displayme = "";
    	for(int i = 0; i<10; i++){
    		  
    	
    		if(sensor3.verifySensor(0x51, i, mybytes))
    		{
    			System.out.println("Works" + i);
    			displayme = " good value " + i;
    			smart.putString("Works ", displayme);
    		}
    		
    	
    	}
    }   
}
Reply With Quote
  #2   Spotlight this post!  
Unread 25-01-2015, 19:08
Fauge7 Fauge7 is offline
Head programmer
FRC #3019 (firebird robotics)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Scottsdale
Posts: 195
Fauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to all
Re: Two questions

Not sure about the i2c module but as for the system.out.print you have to look at the riolog, its the system log but for the robot.

found at Window->Show View->Other->general->RioLog
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 11:52.

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