I know this is irritating, but if anyone can give me an idea about the code below it would be OK,
My knowledge for programming ended with C++ VERY basic,, way back with DOS 5 and basic computing maybe.. I would know more..
The code that follows below is being utilized to do simple Bar code to simulate CV using a Pixy 2 and a Mega 2650. (IT is a simple frame assembly with 4 wheels)
It is suppose to follow you around using Pixycam's utilization of bar code and shape detection)
It is basic not for some high end production.
It is being implemented with
X4 2.5" CIM Motors,
Omni wheels,
Talon speed Controllers
PDP, VEX type,
has it running on 12 V PSU/BAttery Conventional
and uses a MEGA 2560 to perform its movements and interface with the Pixy 2..
Now I am helping the group since no one has the desire to help the project.
Main Question:
Everytime they compile, the IDE displays, "Serial Port does not work"
The code follows below.
For Forum Admins, if there is a violation do tell, I have read the general guidelines.
I am simply asking for a quick, this is that and what are you doing type of response.
Or do I just consult the libraries concerned with the codes attached?
Thank You for any idea.... any thought is good even negative ones...
===============================
//
// begin license header
//
// This file is part of Pixy CMUcam5 or "Pixy" for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// cmucam@cs.cmu.edu. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//
#include <Pixy2.h>
#include <PIDLoop.h>
#include <ZumoMotors.h>
#include <ZumoBuzzer.h>
#include <Servo.h>
// Zumo speeds, maximum allowed is 400
// speeds, maximum allowed is 180
//#define ZUMO_FAST 200
//#define ZUMO_SLOW 150
#define ZUMO_FAST 10
#define ZUMO_SLOW 5
#define X_CENTER (pixy.frameWidth/2)
Pixy2 pixy;
ZumoMotors motors;
ZumoBuzzer buzzer;
Servo FR;
Servo FL;
Servo BR;
Servo BL;
PIDLoop headingLoop(5000, 0, 0, false);
void setup()
{
Serial.begin(115200);
Serial.print("Starting...\n");
motors.setLeftSpeed(0);
motors.setRightSpeed(0);
FR.attach(10);
FL.attach(8);
BL.attach(9);
BR.attach(11);
FR.write(90);
FL.write(90);
BL.write(90);
BR.write(90);
delay(1000);
pixy.init();
// Turn on both lamps, upper and lower for maximum exposure
pixy.setLamp(1, 1);
// change to the line_tracking program. Note, changeProg can use partial strings, so for example,
// you can change to the line_tracking program by calling changeProg("line") instead of the whole
// string changeProg("line_tracking")
pixy.changeProg("line");
// look straight and down
pixy.setServos(500, 1000);
}
void loop()
{
int8_t res;
int32_t error;
int left, right;
char buf[96];
// Get latest data from Pixy, including main vector, new intersections and new barcodes.
res = pixy.line.getMainFeatures();
// If error or nothing detected, stop motors
if (res<=0)
{
motors.setLeftSpeed(0);
motors.setRightSpeed(0);
stopMe();
buzzer.playFrequency(500, 50, 15);
Serial.print("stop ");
Serial.println(res);
return;
}
// We found the vector...
/*
if (res&LINE_VECTOR)
{
// Calculate heading error with respect to m_x1, which is the far-end of the vector,
// the part of the vector we're heading toward.
error = (int32_t)pixy.line.vectors->m_x1 - (int32_t)X_CENTER;
pixy.line.vectors->print();
// Perform PID calcs on heading error.
headingLoop.update(error);
// separate heading into left and right wheel velocities.
left = headingLoop.m_command;
right = -headingLoop.m_command;
// If vector is heading away from us (arrow pointing up), things are normal.
if (pixy.line.vectors->m_y0 > pixy.line.vectors->m_y1)
{
// ... but slow down a little if intersection is present, so we don't miss it.
if (pixy.line.vectors->m_flags&LINE_FLAG_INTERSECTION_PRESENT)
{
left += ZUMO_SLOW;
right += ZUMO_SLOW;
SpinL(100);
}
else // otherwise, pedal to the metal!
{
FF(100);
left += ZUMO_FAST;
right += ZUMO_FAST;
}
}
else // If the vector is pointing down, or down-ish, we need to go backwards to follow.
{
BB(100);
left -= ZUMO_SLOW;
right -= ZUMO_SLOW;
}
LL(left);
RR(right);
motors.setLeftSpeed(left);
motors.setRightSpeed(right);
}
// If intersection, do nothing (we've already set the turn), but acknowledge with a beep.
if (res&LINE_INTERSECTION)
{
buzzer.playFrequency(1000, 100, 15);
pixy.line.intersections->print();
}
*/
// If barcode, acknowledge with beep, and set left or right turn accordingly.
// When calling setNextTurn(), Pixy will "execute" the turn upon the next intersection,
// making the left or right branch in the intersection the new main vector, depending on
// the angle passed to setNextTurn(). The robot will then follow the branch.
// If the turn is not set, Pixy will choose the straight(est) path by default, but
// the default turn can be changed too by calling setDefaultTurn(). The default turn
// is normally 0 (straight).
if (res&LINE_BARCODE)
{
pixy.line.barcodes->print();
// code==0 is our left-turn sign
if (pixy.line.barcodes->m_code==0)
//pixy.line.setNextTurn(90);// 90 degrees is a left turn
FF(20);
// code==1 is our right-turn sign
else if (pixy.line.barcodes->m_code==1)
//pixy.line.setNextTurn(-90); // -90 is a right turn
LL(20);
// code==2 is our right-turn sign
else if (pixy.line.barcodes->m_code==1)
//pixy.line.setNextTurn(-90); // -90 is a right turn
RR(20);
}
}
// FF 90 TO 180
void FF(int x) {
Serial.println("Forward FF");
FR.write(x);
BR.write(x);
FL.write(x);
BL.write(x);
}
//BB 90 TO 180
void BB(int x) {
Serial.println("Backward BB ");
FR.write(x);
BR.write(x);
FL.write(x);
BL.write(x);
}
// RR 0 TO 90 forward
void RR(int x) {
Serial.println("RIGHT RR ");
FR.write(180 - x);
BR.write(x);
FL.write(x);
BL.write(180 - x);
}
//LL 90 TO 180 forward
void LL(int x) {
Serial.println("LEFT LL ");
FR.write(180 - x);
BR.write(x);
FL.write(x);
BL.write(180 - x);
}
//DFR 0 TO 90
void DFR (int x) {
Serial.println("Diagonal 1st QD DFR ");
BR.write(x);
FL.write(x);
}
//DBL 90 TO 180
void DBL(int x) {
Serial.println("Diagonal 3rd QD DBL ");
BR.write(x);
FL.write(x);
}
//DFL 0 TO 90
void DFL(int x) {
Serial.println("Diagonal 2nd QD DFL ");
BL.write(x);
FR.write(x);
}
// DBR 90 TO 180
void DBR(int x) {
Serial.println("Diagonal 4nd QD DBR ");
BL.write(x);
FR.write(x);
}
// Stop
void stopMe() {
Serial.println("Leave me alone I am in my DEAD ZONE ");
FR.write(90);
BR.write(90);
FL.write(90);
BL.write(90);
}
void SpinR(int x) {
Serial.println("SPin on my back ");
FL.write(x);
BL.write(x);
FR.write(180 - x);
BR.write(180 - x);
}
void SpinL(int x) {
Serial.println("Spin on my Back Right wheel ");
FL.write(180 - x);
BL.write(180 - x);
FR.write(x);
BR.write(x);
}