OCCRA
Go to Post Sooo....in the famous words of Douglas Adams, Don't Panic. - Conor Ryan [more]
Home
Go Back   Chief Delphi > Technical > Electrical
CD-Media  
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 12-22-2017, 04:17 PM
minisolarclown's Avatar
minisolarclown minisolarclown is offline
Registered User
FRC #3603 (Cyber Coyotes)
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2015
Location: Reed City
Posts: 81
minisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really nice
How do I use the LIDAR with a NavX-mxp?

I made a similar post to this on the Java forum, but now I'm thinking my problem could be electrical because I've had no success whatsoever. I'm using a LIDAR Lite v3, connected to the I2C port on a NavX-mxp. Has anyone here had any success? I'm re-reading the datasheet and it says something about putting an electrolytic capacitor between the VCC and GND pins on the Lidar. Is that actually necessary? I read somewhere else that the Lidar needs pull-up resistors, but I also read the roboRIO has them built in. Any help is appreciated!
Reply With Quote
  #2   Spotlight this post!  
Unread 12-22-2017, 05:56 PM
solomondg's Avatar
solomondg solomondg is offline
Registered User
AKA: Solomon
FRC #2898 (Flying Hedgehogs)
Team Role: Leadership
 
Join Date: Aug 2016
Rookie Year: 2016
Location: Portland, Oregon
Posts: 114
solomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant futuresolomondg has a brilliant future
Re: How do I use the LIDAR with a NavX-mxp?

First I'd try to get it working on the built-in RoboRIO i2c port. You shouldn't need pullups (the RIO does have them internally iirc), but you will absolutely want a capacitor bridging +5 and ground. ~1000uF and ≥25v tolerance should work fine. Make sure to get the polarity right otherwise things will get explodey.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-22-2017, 06:20 PM
minisolarclown's Avatar
minisolarclown minisolarclown is offline
Registered User
FRC #3603 (Cyber Coyotes)
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2015
Location: Reed City
Posts: 81
minisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really nice
Re: How do I use the LIDAR with a NavX-mxp?

I thought the built in I2C port only outputs 3.3v instead of 5v. Should I still use that instead?
Reply With Quote
  #4   Spotlight this post!  
Unread 12-22-2017, 06:26 PM
firecrafty's Avatar
firecrafty firecrafty is offline
Autonomous Driver
AKA: Ryan Blue
FRC #1018 (Pike RoboDevils)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2016
Location: Indianapolis
Posts: 203
firecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond reputefirecrafty has a reputation beyond repute
Re: How do I use the LIDAR with a NavX-mxp?

Quote:
Originally Posted by minisolarclown View Post
I thought the built in I2C port only outputs 3.3v instead of 5v. Should I still use that instead?
No, do not use that. The LIDAR lite will only function with 5v power, and, as you said, the RoboRIO only outputs 5v on the MXP, not the onboard I2C. You do, however, have to make sure that the navX has it's DC voltage jumper in the 5v position.
__________________
"Programming is a science. Writing beautiful code is an art."
Any views I express are my own and do not necessarily reflect those of my team.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-22-2017, 08:26 PM
Tom Line's Avatar
Tom Line Tom Line is offline
Don't lay blame. Fix probems.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 3,232
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: How do I use the LIDAR with a NavX-mxp?

Quote:
Originally Posted by firecrafty View Post
No, do not use that. The LIDAR lite will only function with 5v power, and, as you said, the RoboRIO only outputs 5v on the MXP, not the onboard I2C. You do, however, have to make sure that the navX has it's DC voltage jumper in the 5v position.
You can actually plug it in to any of the dio power - they are all 5V.

Be careful on lidar versions and code. V1 will not work with V3 code, and vice versa. So make sure the code you're using matches your version.
Reply With Quote
  #6   Spotlight this post!  
Unread 12-23-2017, 09:25 AM
minisolarclown's Avatar
minisolarclown minisolarclown is offline
Registered User
FRC #3603 (Cyber Coyotes)
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2015
Location: Reed City
Posts: 81
minisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really nice
Re: How do I use the LIDAR with a NavX-mxp?

The NavX is set to 5v. Would the missing capacitor affect my inability to communicate with the Lidar? Or should I go back to the programming forum? I thought the capacitor only served to regulate voltage spikes.
Reply With Quote
  #7   Spotlight this post!  
Unread 12-23-2017, 01:58 PM
GlassMaker's Avatar
GlassMaker GlassMaker is offline
Registered User
AKA: Carlos
FRC #0103 (Cybersonics)
Team Role: Mentor
 
Join Date: Mar 2017
Rookie Year: 2015
Location: Kintnersville, PA
Posts: 26
GlassMaker will become famous soon enough
Re: How do I use the LIDAR with a NavX-mxp?

We got the Lidar Lite v3 working last year on the I2C bus along with Pixy cams. Just note it worked well on our practice field but not so much in last years competition. Our practice field was mostly plywood, but the real field was a lot of clear plastic. The laser went right through it. Kind of a palm to forehead moment when we figure out what was happening, so just giving a heads up to consider what the target is.
We connected the Lidar Lite to the NavX headers and I see you have already set it to 5 volt. We connected in a capacitor close to the Lidar per the manual. Keep your I2C bus line as short as possible, preferably shielded cable to minimize noise. Only ground the one side of the shield wire.
Here is the code we started with (we program in Java):

In RobotMap:
public static Lidar lidar;
lidar = new Lidar(I2C.Port.kMXP, (byte) 0x62);

Create a new class called Lidar and put this in:

import java.nio.ByteBuffer;
import java.util.TimerTask;

import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.I2C.Port;

public class Lidar {

private I2C i2c;
private java.util.Timer updater;
private ByteBuffer buffer = ByteBuffer.allocateDirect(3);
private volatile int distance;
private int measurementCount = 0;

private static final int LIDAR_BUSY_MASK = 0x01;
private static final int LIDAR_COMMAND_ACQUIRE_WITHOUT_CORRECTION = 0x03;
private static final int LIDAR_COMMAND_ACQUIRE_WITH_CORRECTION = 0x04;
private static final int LIDAR_CONFIG_REGISTER = 0x00;
private static final int LIDAR_STATUS_REGISTER = 0x01;
private static final int LIDAR_SIG_COUNT = 0x02;
private static final int LIDAR_ACQ_CONFIG = 0x04;
private static final int LIDAR_THRESHOLD_BYPASS = 0x1c;
private static final int LIDAR_DISTANCE_REGISTER = 0x8f;

private static final int UPDATE_PERIOD = 20; // in milliseconds
private static final int RETRY_COUNT = 50;

public Lidar(Port port, byte address) {
i2c = new I2C(port, address);

setup();

updater = new java.util.Timer();
updater.schedule(new TimerTask() {
@Override
public void run() {
distance = getUpdatedDistance();
}
}, 0, UPDATE_PERIOD);
System.out.println("Started");
}

// Distance in cm
public int getDistance() {
return distance;
}

public void setup() {
i2c.write(LIDAR_SIG_COUNT, 0x80);
sleep(1);
i2c.write(LIDAR_ACQ_CONFIG, 0x08);
sleep(1);
i2c.write(LIDAR_THRESHOLD_BYPASS, 0x00);
sleep(1);
}

// Update distance variable
private int getUpdatedDistance() {
int command = (measurementCount % 100 == 0 ? LIDAR_COMMAND_ACQUIRE_WITH_CORRECTION : LIDAR_COMMAND_ACQUIRE_WITHOUT_CORRECTION);
i2c.write(LIDAR_CONFIG_REGISTER, command); // Initiate measurement
/*if (measurementCount++ % 50 == 0) {
System.out.println("count = " + measurementCount + ", distance = " + distanceValue);
}*/
measurementCount++;
int busyCount = 0;
do {
sleep(1);
int status = readByte(LIDAR_STATUS_REGISTER);
boolean busy = (status & LIDAR_BUSY_MASK) == LIDAR_BUSY_MASK;
if (!busy) {
return readShort(LIDAR_DISTANCE_REGISTER);
} else {
busyCount++;
}
/*SmartDashboard.putNumber("status", status);
SmartDashboard.putBoolean("busyFlag", busy);*/
} while (busyCount < RETRY_COUNT);
System.out.println("Distance read timed out");
return distance;
}

private void sleep(long millis) {
try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); }
}

private int readByte(int register) {
buffer.put(0, (byte) register);
i2c.writeBulk(buffer, 1);
i2c.readOnly(buffer, 1);
return buffer.get(0) & 0xFF;
}

private int readShort(int register) {
buffer.put(0, (byte) register);
i2c.writeBulk(buffer, 1);
i2c.readOnly(buffer, 2);
return buffer.getShort(0) & 0xFFFF;
}

}

The lidar unit will start up as soon as the RobotMap is initialized.
Use RobotMap.lidar.getDistance() to get the distance value in cm where needed. This should get you started.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-23-2017, 02:39 PM
Tungrus's Avatar
Tungrus Tungrus is offline
Registered User
no team
 
Join Date: Mar 2013
Location: Somewhere
Posts: 582
Tungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond reputeTungrus has a reputation beyond repute
Re: How do I use the LIDAR with a NavX-mxp?

Quote:
Originally Posted by minisolarclown View Post
The NavX is set to 5v. Would the missing capacitor affect my inability to communicate with the Lidar? Or should I go back to the programming forum? I thought the capacitor only served to regulate voltage spikes.
Capacitor works as voltage stabilizer, so it must be something else.
Reply With Quote
  #9   Spotlight this post!  
Unread 12-23-2017, 04:10 PM
marshall's Avatar
marshall marshall is offline
"Who's Marshall?"
FRC #0900 (The Zebracorns)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2003
Location: North Carolina
Posts: 3,065
marshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond repute
Re: How do I use the LIDAR with a NavX-mxp?

Quote:
Originally Posted by minisolarclown View Post
The NavX is set to 5v. Would the missing capacitor affect my inability to communicate with the Lidar? Or should I go back to the programming forum? I thought the capacitor only served to regulate voltage spikes.
Have you used the LIDAR with an Arduino just to test that it is working?
__________________
"La mejor salsa del mundo es la hambre" - Miguel de Cervantes
"The future is unwritten" - Joe Strummer
"Simplify, then add lightness" - Colin Chapman
Clarke's Laws
Reply With Quote
  #10   Spotlight this post!  
Unread 12-23-2017, 05:15 PM
GlassMaker's Avatar
GlassMaker GlassMaker is offline
Registered User
AKA: Carlos
FRC #0103 (Cybersonics)
Team Role: Mentor
 
Join Date: Mar 2017
Rookie Year: 2015
Location: Kintnersville, PA
Posts: 26
GlassMaker will become famous soon enough
Re: How do I use the LIDAR with a NavX-mxp?

I posted this earlier but must have done something wrong as my post has not shown up.
Marshall brings up a good point. Testing it on an Arduino would let you be sure it is working.
We setup a Lidar Lite v3 and Pixy cams last year using I2C but did not end up using the Lidar after the first competition. Worked great in our plywood practice field but not so well on the clear plastic of the competition field. Lidar goes through clear plastic. Kind of one of those palm to forehead moments, so when you get it working consider what your target is going to be.
We connected the Lidar to the I2C terminals on the the NavX board. We did mount the capacitor close to the Lidar per the instruction manual. Keep the I2C wiring as short as you can and use shielded wire if you have it. We did start off with regular wire, but the shielded wire helps cut down on noise issues we saw on the I2C bus.

Here is code that should get it up and working providing the unit is functional and the wiring is right

In RobotMap:
Code:
public static Lidar lidar;
lidar = new Lidar(I2C.Port.kMXP, (byte) 0x62);
Create a new class called Lidar and put this in:

Code:
import java.nio.ByteBuffer;
import java.util.TimerTask;

import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.I2C.Port;



public class Lidar {
	
	private I2C i2c;
	private java.util.Timer updater;
	private ByteBuffer buffer = ByteBuffer.allocateDirect(3);
	private volatile int distance;
	private int measurementCount = 0;
	
	private static final int LIDAR_BUSY_MASK = 0x01;
	private static final int LIDAR_COMMAND_ACQUIRE_WITHOUT_CORRECTION = 0x03;
	private static final int LIDAR_COMMAND_ACQUIRE_WITH_CORRECTION = 0x04;
	private static final int LIDAR_CONFIG_REGISTER = 0x00;
	private static final int LIDAR_STATUS_REGISTER = 0x01;
	private static final int LIDAR_SIG_COUNT = 0x02;
	private static final int LIDAR_ACQ_CONFIG = 0x04;
	private static final int LIDAR_THRESHOLD_BYPASS = 0x1c;
	private static final int LIDAR_DISTANCE_REGISTER = 0x8f;
	
	private static final int UPDATE_PERIOD = 20; // in milliseconds
	private static final int RETRY_COUNT = 50;
	
	public Lidar(Port port, byte address) {
		i2c = new I2C(port, address);
		
		setup();
		
		updater = new java.util.Timer();
		updater.schedule(new TimerTask() {
			@Override
			public void run() {
				distance = getUpdatedDistance();
			}
		}, 0, UPDATE_PERIOD);
		System.out.println("Started");
	}
	
	// Distance in cm
	public int getDistance() {
		return distance;
	}
	
	public void setup() {
		i2c.write(LIDAR_SIG_COUNT, 0x80);
		sleep(1);
		i2c.write(LIDAR_ACQ_CONFIG, 0x08);
		sleep(1);
		i2c.write(LIDAR_THRESHOLD_BYPASS, 0x00);
		sleep(1);
	}
	
	// Update distance variable
	private int getUpdatedDistance() {
		int command = (measurementCount % 100 == 0 ? LIDAR_COMMAND_ACQUIRE_WITH_CORRECTION : LIDAR_COMMAND_ACQUIRE_WITHOUT_CORRECTION);
		i2c.write(LIDAR_CONFIG_REGISTER, command); // Initiate measurement
		/*if (measurementCount++ % 50 == 0) {
			System.out.println("count = " + measurementCount + ", distance = " + distanceValue);
		}*/
		measurementCount++;
		int busyCount = 0;
		do {
			sleep(1);
			int status = readByte(LIDAR_STATUS_REGISTER);
			boolean busy = (status & LIDAR_BUSY_MASK) == LIDAR_BUSY_MASK;
			if (!busy) {
				return readShort(LIDAR_DISTANCE_REGISTER);
			} else {
				busyCount++;
			}
			/*SmartDashboard.putNumber("status", status);
			SmartDashboard.putBoolean("busyFlag", busy);*/
		} while (busyCount < RETRY_COUNT);
		System.out.println("Distance read timed out");
		return distance;
	}
	
	private void sleep(long millis) {
		try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); }
	}
	
	private int readByte(int register) {
		buffer.put(0, (byte) register);
		i2c.writeBulk(buffer, 1);
		i2c.readOnly(buffer, 1);
		return buffer.get(0) & 0xFF;
	}
	
	private int readShort(int register) {
		buffer.put(0, (byte) register);
		i2c.writeBulk(buffer, 1);
		i2c.readOnly(buffer, 2);
		return buffer.getShort(0) & 0xFFFF;
	}
	
}
Assuming wiring is correct and the Lidar is functional the Lidar unit will start up when the Robot is initialized. Use RobotMap.lidar.getDistance() to get the distance in cm.

This should get you started.
Reply With Quote
  #11   Spotlight this post!  
Unread 12-25-2017, 06:33 PM
minisolarclown's Avatar
minisolarclown minisolarclown is offline
Registered User
FRC #3603 (Cyber Coyotes)
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2015
Location: Reed City
Posts: 81
minisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really niceminisolarclown is just really nice
Re: How do I use the LIDAR with a NavX-mxp?

How would I get it to work with an iterative robot? And how much of a deal is I2C noise? When I get home I'm going to work on getting my Arduino board to work with it.
Reply With Quote
  #12   Spotlight this post!  
Unread 12-25-2017, 07:01 PM
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 546
slibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond repute
Re: How do I use the LIDAR with a NavX-mxp?

Quote:
Originally Posted by minisolarclown View Post
how much of a deal is I2C noise?
If you have $200, hereís a great way to spend it that can help answer your question. https://www.amazon.com/Saleae-4-Chan...eywords=Saleae. Itís a seriously beautiful product and very helpful for debugging comm protocols like i2c, spi and uart.

Alternatively, an oscilloscope can show you the signal quality, although it wonít decode the protocol for you.

Generally, be sure to avoid running i2c wires near motors, research i2c wire length guidance, and review if running at the slower speed (100khz) is viable, as that will be somewhat less sensitive to noise than fast mode (400khz).
Reply With Quote
  #13   Spotlight this post!  
Unread 12-27-2017, 10:25 PM
GlassMaker's Avatar
GlassMaker GlassMaker is offline
Registered User
AKA: Carlos
FRC #0103 (Cybersonics)
Team Role: Mentor
 
Join Date: Mar 2017
Rookie Year: 2015
Location: Kintnersville, PA
Posts: 26
GlassMaker will become famous soon enough
Re: How do I use the LIDAR with a NavX-mxp?

To run in Iterative robot you would still need to create the Lidar class and insert the code. You would put the items from the Robotmap section in the area where you initialize your robot. You would then call lidar.getDistance() where you need the distance value.

The noise on the line can be an issue. Last year our main Pixy camera and the Lidar ended up about as far away from the roborio as was possible making controlling noise difficult. It was literally placed diagonally across the robot from the roborio both horizontally and vertically. This caused our lines to be longer then they should have been. Still well within limits for I2C but longer then we would have preferred. They also had to go around several power wires, Talons, and were right over two motors for our right front drive. On our particular bot the worst noise offender seemed to be our 775pro powered shooter which happened to have a second pixy camera located near it, also on the I2C bus. Like I said earlier, changing over to shielded wire helped. You should note that we only ground one end of the shield wire, in our case the end closest to the roborio to prevent weird loops in the shield. We still did have occasional issues though where the I2C bus would lock up. What we found was that the I2C line would hang with the one line held high indefinitely. We believe that the noise from the motor(s) would occasionally trigger a spike on the I2C bus that made the bus think there was another I2C master on the line. Being that I2C is a multi-master multi-slave system the roborio master would then simply wait for the new master to complete it's transmission which of course is never going to happen. We never did put a scope on the line to confirm this, but every time it occurred a digital logic probe showed the lines stuck in the same manner that seemed to indicate the transmission was waiting for completion. Now mind our theory on this could be wrong and if anyone else has better info or a better theory on the lock up problem we would be glad to hear it. In the end we did find that if we forced the line that was held high to a low state it and then released it the bus would restart. It should be noted that the I2C bus on the Roborio is a software controlled bus using two special DIO pins. On the MXP board they are DIO pins 24 and 25. What our one programming mentor did was to write a library file for the Roborio at the roborio level allowing us to selectively switch MXP pins 24 and 25 from I2C mode to DIO mode and back. By doing this we were able to track when an "event" occurred, switch modes to allow us to control the pins to reset the bus, and then switch the pins back into I2C mode to continue operations. Like I said this did not happen often after changing over to good wire, but we wanted to be sure it would never be a problem.

The following links are for the code we ended the season with. It is very similar to the code above but it adds in the ability to reset the bus as described. Just note that installing this takes a bit more effort then the code listed previously.

I have put our last years code on github. The fault correction for the I2C bus is here https://github.com/Cybersonics/MXPSp...xp_specialness.
To install this copy the four files there and follow the directions in the readme file. Just remember to change the team number following roborio- to your team number. What you will be doing is installing the libmxp_specialness.so file directly onto your roborio using pscp. You are then using putty to ssh into the roborio and set the file to executable so the ReliableI2C class can use it.
You will probably need to add the jna.jar to your build path. Here is a copy of what we used https://github.com/Cybersonics/2017S...ter/build/jars
You will also need the Lidar and ReliableI2C classes to add to your code. The Lidar code here is similar to the code above but it uses the ReliableI2C class to find when there is a problem and correct for it. To initialize the whole group you will need to add
Code:
    public static Pixy2 pixy;
    public static Relay relay0, relay1;
    public static Lidar lidar;
    //public static DigitalOutput lidarReset;
    public static Ultrasonic ultrasonic;

    public static void init() {
        ReliableI2C.init();
        pixy = new Pixy2(ReliableI2C.openDevice(I2CPort.MXP, (byte) 0x54));
        lidar = new Lidar(ReliableI2C.openDevice(I2CPort.MXP, (byte) 0x62));
to your robot initialization. You would still use lidar.getDistance() to get the distance in cm.
Reply With Quote
  #14   Spotlight this post!  
Unread 12-27-2017, 10:37 PM
GlassMaker's Avatar
GlassMaker GlassMaker is offline
Registered User
AKA: Carlos
FRC #0103 (Cybersonics)
Team Role: Mentor
 
Join Date: Mar 2017
Rookie Year: 2015
Location: Kintnersville, PA
Posts: 26
GlassMaker will become famous soon enough
Re: How do I use the LIDAR with a NavX-mxp?

To run in Iterative robot you would still need to create the Lidar class and insert the code. You would put the items from the Robotmap section in the area where you initialize your robot. You would then call lidar.getDistance() where you need the distance value.

The noise on the line can be an issue. Last year our main Pixy camera and the Lidar ended up about as far away from the roborio as was possible making controlling noise difficult. It was literally placed diagonally across the robot from the roborio both horizontally and vertically. This caused our lines to be longer then they should have been. Still well within limits for I2C but longer then we would have preferred. They also had to go around several power wires, Talons, and were right over two motors for our right front drive. On our particular bot the worst noise offender seemed to be our 775pro powered shooter which happened to have a second pixy camera located near it, also on the I2C bus. Like I said earlier, changing over to shielded wire helped. You should note that we only ground one end of the shield wire, in our case the end closest to the roborio to prevent weird loops in the shield. We still did have occasional issues though where the I2C bus would lock up. What we found was that the I2C line would hang with the one line held high indefinitely. We believe that the noise from the motor(s) would occasionally trigger a spike on the I2C bus that made the bus think there was another I2C master on the line. Being that I2C is a multi-master multi-slave system the roborio master would then simply wait for the new master to complete it's transmission which of course is never going to happen. We never did put a scope on the line to confirm this, but every time it occurred a digital logic probe showed the lines stuck in the same manner that seemed to indicate the transmission was waiting for completion. Now mind our theory on this could be wrong and if anyone else has better info or a better theory on the lock up problem we would be glad to hear it. In the end we did find that if we forced the line that was held high to a low state it and then released it the bus would restart. It should be noted that the I2C bus on the Roborio is a software controlled bus using two special DIO pins. On the MXP board they are DIO pins 24 and 25. What our one programming mentor did was to write a library file for the Roborio at the roborio level allowing us to selectively switch MXP pins 24 and 25 from I2C mode to DIO mode and back. By doing this we were able to track when an "event" occurred, switch modes to allow us to control the pins to reset the bus, and then switch the pins back into I2C mode to continue operations. Like I said this did not happen often after changing over to good wire, but we wanted to be sure it would never be a problem.

The following links are for the code we ended the season with. It is very similar to the code above but it adds in the ability to reset the bus as described. Just note that installing this takes a bit more effort then the code listed previously.

The fault correction for the I2C bus is here https://github.com/Cybersonics/MXPSp...xp_specialness.
To install this copy the four files there and follow the directions in the readme file. Just remember to change the team number following roborio- to your team number. What you will be doing is installing the libmxp_specialness.so file directly onto your roborio using pscp. You are then using putty to ssh into the roborio and set the file to executable so the ReliableI2C class can use it.
You will probably need to add the jna.jar to your build path. Here is a copy of what we used https://github.com/Cybersonics/2017S...ter/build/jars
You will also need the Lidar and ReliableI2C classes to add to your code. The Lidar code here is similar to the code above but it uses the ReliableI2C class to find when there is a problem and correct for it. To initialize the whole group you will need to add
Code:
    public static Pixy2 pixy;
    public static Relay relay0, relay1;
    public static Lidar lidar;
    //public static DigitalOutput lidarReset;
    public static Ultrasonic ultrasonic;

    public static void init() {
        ReliableI2C.init();
        pixy = new Pixy2(ReliableI2C.openDevice(I2CPort.MXP, (byte) 0x54));
        lidar = new Lidar(ReliableI2C.openDevice(I2CPort.MXP, (byte) 0x62));
to your robot initialization. You would still use lidar.getDistance() to get the distance in cm.
Reply With Quote
  #15   Spotlight this post!  
Unread 12-27-2017, 10:39 PM
GlassMaker's Avatar
GlassMaker GlassMaker is offline
Registered User
AKA: Carlos
FRC #0103 (Cybersonics)
Team Role: Mentor
 
Join Date: Mar 2017
Rookie Year: 2015
Location: Kintnersville, PA
Posts: 26
GlassMaker will become famous soon enough
Re: How do I use the LIDAR with a NavX-mxp?

To run in Iterative robot you would still need to create the Lidar class and insert the code. You would put the items from the Robotmap section in the area where you initialize your robot. You would then call lidar.getDistance() where you need the distance value.

The noise on the line can be an issue. Last year our main Pixy camera and the Lidar ended up about as far away from the roborio as was possible making controlling noise difficult. It was literally placed diagonally across the robot from the roborio both horizontally and vertically. This caused our lines to be longer then they should have been. Still well within limits for I2C but longer then we would have preferred. They also had to go around several power wires, Talons, and were right over two motors for our right front drive. On our particular bot the worst noise offender seemed to be our 775pro powered shooter which happened to have a second pixy camera located near it, also on the I2C bus. Like I said earlier, changing over to shielded wire helped. You should note that we only ground one end of the shield wire, in our case the end closest to the roborio to prevent weird loops in the shield. We still did have occasional issues though where the I2C bus would lock up. What we found was that the I2C line would hang with the one line held high indefinitely. We believe that the noise from the motor(s) would occasionally trigger a spike on the I2C bus that made the bus think there was another I2C master on the line. Being that I2C is a multi-master multi-slave system the roborio master would then simply wait for the new master to complete it's transmission which of course is never going to happen. We never did put a scope on the line to confirm this, but every time it occurred a digital logic probe showed the lines stuck in the same manner that seemed to indicate the transmission was waiting for completion. Now mind our theory on this could be wrong and if anyone else has better info or a better theory on the lock up problem we would be glad to hear it. In the end we did find that if we forced the line that was held high to a low state it and then released it the bus would restart. It should be noted that the I2C bus on the Roborio is a software controlled bus using two special DIO pins. On the MXP board they are DIO pins 24 and 25. What our one programming mentor did was to write a library file for the Roborio at the roborio level allowing us to selectively switch MXP pins 24 and 25 from I2C mode to DIO mode and back. By doing this we were able to track when an "event" occurred, switch modes to allow us to control the pins to reset the bus, and then switch the pins back into I2C mode to continue operations. Like I said this did not happen often after changing over to good wire, but we wanted to be sure it would never be a problem.
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 08:39 PM.

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


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi