|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#9
|
||||
|
||||
|
Re: Vision tracking and related questions
Your main software options are Grip and RoboRealm. Grip feel unfinished and doesn't yet function well, as it is a work in progress. I greatly prefer RoboRealm.
I have succeeded in getting working RoboRealm vision processing this week and I can even adjust the robot's position to within 15 pixels of the center of the vision target. This is my RoboRealm pipeline: ![]() The Axis Camera module is in order to connect with an IP camera. RoboRealm can only use a USB camera if you're running RoboRealm on that device. (Aka in order to use a USB camera on the robot you would need a Windows machine ON the robot, such as a Kangaroo). The Adaptive Threshold gray scales the image and filters it so that only intensities of ~190-210 show, which is about the intensity of the reflective tape when an LED light is shown on it. Convex hull fills in the target U shape and makes it a rectangle. My blob filter removes all blobs that have made it this far except the largest blob. (If you want multiple targets to come through, remove blobs based on area instead of largest only.) Center of Gravity gives the X coordinate of the center of the target in pixels. Network Tables publishes the center of gravity information and image dimensions to the network tables, in order to be read in by your program. The following is my C++ code that is compatible with the above RoboRealm pipeline, look mainly at the Test() function: Code:
/*
* Robot.cpp
*
* Created on: Feb 7, 2016
* Author: Michael Conard
**/
#include "WPILib.h"
#include "Shooter.h"
#include "Constants.h"
class Robot: public SampleRobot
{
private:
RobotDrive* mRobot;
BuiltInAccelerometer* mAcc; //RoboRio accelerometer
Joystick* mStick; //Xbox controller
CANTalon* mFrontLeft;
CANTalon* mFrontRight;
CANTalon* mRearLeft;
CANTalon* mRearRight;
Shooter* mShooter; //Shooter class object
std::shared_ptr<NetworkTable> roboRealm; //Network table object, communicate with RoboRealm
public:
Robot(); //Constructor
~Robot(); //Destructor
void OperatorControl();
void Autonomous();
void Test();
void Disabled();
};
Robot::Robot():roboRealm(NetworkTable::GetTable("RoboRealm")) //Construct network object within the scope of Robot
{
printf("File %18s Date %s Time %s Object %p\n",__FILE__,__DATE__, __TIME__, this);
mStick = new Joystick(XBOX::DRIVER_PORT);
mAcc = new BuiltInAccelerometer();
mShooter = new Shooter(VIRTUAL_PORT::SHOOTER_LEFT_WHEEL, VIRTUAL_PORT::SHOOTER_RIGHT_WHEEL,
VIRTUAL_PORT::SHOOTER_ANGLE, PWM_PORT::PUSH_SERVO_PORT, mStick);
mFrontLeft = new CANTalon(VIRTUAL_PORT::LEFT_FRONT_DRIVE);
mFrontRight = new CANTalon(VIRTUAL_PORT::RIGHT_FRONT_DRIVE);
mRearLeft = new CANTalon(VIRTUAL_PORT::LEFT_REAR_DRIVE);
mRearRight = new CANTalon(VIRTUAL_PORT::RIGHT_REAR_DRIVE);
mRobot = new RobotDrive(mFrontLeft, mRearLeft, mFrontRight, mRearRight);
mRobot->SetSafetyEnabled(false);
}
Robot::~Robot()
{
delete mRobot;
delete mAcc;
delete mStick;
delete mFrontRight;
delete mFrontLeft;
delete mRearRight;
delete mRearLeft;
delete mShooter;
}
void Robot::Disabled()
{
printf("\nDisabled\n");
}
void Robot::OperatorControl() //standard driving and shooter control
{
while(IsOperatorControl() && IsEnabled())
{
//printf("X Acc: %f, Y Acc: %f. Z Acc. %f\n", mAcc->GetX(), mAcc->GetY(), mAcc->GetZ());
mRobot->ArcadeDrive(-mStick->GetRawAxis(XBOX::LEFT_Y_AXIS), -mStick->GetRawAxis(XBOX::LEFT_X_AXIS)); //standard drive
if(mStick->GetRawAxis(XBOX::LEFT_TRIGGER_AXIS) >= 0.5) //spin wheels to suck ball in
{
mShooter->ActivateMotors(-.8);
}
else if(mStick->GetRawAxis(XBOX::RIGHT_TRIGGER_AXIS) >= 0.5) //activate wheels, wait for full speed, shoot ball
{
mShooter->ShootBall();
}
else
{
mShooter->DisableMotors();
}
Wait(0.02);
}
}
void Robot::Test() //tests aligning with vision target
{
double imageWidth = roboRealm->GetNumber("IMAGE_WIDTH", 320); //get image width
double xPosition;
double distFromCenter;
while(IsTest() && IsEnabled())
{
xPosition = roboRealm->GetNumber("COG_X", -1.0); //get center of gravity of vision target
distFromCenter = imageWidth/2.0 - xPosition; //positive means object too far right, negative means too far left
printf("xPosition: %f, distFromCenter: %f\n", xPosition, distFromCenter);
if(xPosition != -1) //if set to default value, network table not found
{
if(distFromCenter > 15) //vision target too far right, spin right
mRobot->ArcadeDrive(0.0,0.40);
else if(distFromCenter < -15) //vision target too far left, spin left
mRobot->ArcadeDrive(0.0,-0.40);
else
{
mRobot->ArcadeDrive(0.0,0.0); //stop, centered within 15 pixels
printf("Centered! "); //lines up with xPosition print above
}
}
else
{
printf("Network table error!!!\n");
}
}
}
void Robot::Autonomous() //aligns with vision target then shoots
{
double imageWidth = roboRealm->GetNumber("IMAGE_WIDTH", 320); //get image width
double xPosition;
double distFromCenter;
while(IsAutonomous() && IsEnabled())
{
xPosition = roboRealm->GetNumber("COG_X", -1.0); //get center of gravity of vision target
distFromCenter = imageWidth/2.0 - xPosition; //positive means object too far right, negative means too far left
if(xPosition != -1) //if set to default value, network table not found
{
if(distFromCenter > 15) //vision target too far right, spin right
mRobot->ArcadeDrive(0.0,0.2);
else if(distFromCenter < -15) //vision target too far left, spin left
mRobot->ArcadeDrive(0.0,-0.2);
else
{
Wait(0.5);
mShooter->ShootBall(); //centered within 15 pixels, shoot ball
}
}
else
{
printf("Network table error!!!\n");
}
Wait(0.02);
}
}
START_ROBOT_CLASS(Robot)
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|