Jeg har ikke nogen solid idé om, hvad der går galt, og jeg håber at få noget input fra jer. Der er en massive række fejl-noteringer .. men nogle af dem synes helt hen i vejret.
Koden hører til i Arduino sammenhæng og er skrevet i notepad.
.h og .cpp er anbragt så Arduino-IDE'en finder dem og kompilerer, så fejlkoderne har jeg fra IDE'en.
Fejlkoder:
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In constructor 'cPen::cPen(cStepper, cStepper)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:11: error: no matching function for call to 'cStepper::cStepper()'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cStepper.h:14: note: candidates are: cStepper::cStepper(int, int, int, int, int, int)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cStepper.h:12: note: cStepper::cStepper(const cStepper&)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:11: error: no matching function for call to 'cStepper::cStepper()'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cStepper.h:14: note: candidates are: cStepper::cStepper(int, int, int, int, int, int)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cStepper.h:12: note: cStepper::cStepper(const cStepper&)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:19: error: new initializer expression list treated as compound expression
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:19: error: no matching function for call to 'cPoint::cPoint(float)'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cPoint.h:7: note: candidates are: cPoint::cPoint(const cPoint&)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cPoint.h:7: note: cPoint::cPoint()
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'void cPen::goToLinear(cPoint)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:36: error: no matching function for call to 'cPen::moveLinear(float, float, float)'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\/cPen.h:20: note: candidates are: void cPen::moveLinear(float, float)
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'cPoints cPen::buildArc(cArc)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:45: error: invalid conversion from 'cPoints*' to 'int'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:45: error: initializing argument 1 of 'cPoints::cPoints(int)'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'float cPen::sinFragX(int, float, float)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:71: error: 'px' cannot be used as a function
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:71: error: expected `)' before ';' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'cPoint cPen::divide(int, float, float)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:77: error: conversion from 'cPoint*' to non-scalar type 'cPoint' requested
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:82: error: expected primary-expression before '<=' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:96: error: expected primary-expression before '>' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:103: error: expected primary-expression before '>=' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:117: error: expected primary-expression before '>=' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:131: error: expected primary-expression before '>=' token
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'void cPen::drawPoints(cPoints)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:154: error: no match for call to '(cPoints) (int&)'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:155: error: no match for call to '(cPoints) (int)'
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp: In member function 'void cPen::moveLinear(float, float)':
G:\NetDownloads\arduino-1.0-windows\arduino-1.0\libraries\cStepper\cPen.cpp:195: error: 'class cStepper' has no member named 'setDirecton'
kode:
- #ifndef cStepper_h
- #define cStepper_h
-
- #include "Arduino.h"
- //#include "cPoint.h"
-
- //#pragma once
-
- class cStepper
- {
- public:
- cStepper( int EA , int EB , int i1 , int i2 , int i3 , int i4 );
- void setMinDelay( float minDelay );
- void setToMaxVelocity() ;
- boolean setVelocity( float Velocity ) ;
-
- void Step( bool Forward ) ;
- void setPosition( float start_position ) ;
- float getPosition() ;
- float getMaxVelocity() ;
-
- boolean getDirection() ;
- void setDirection( boolean forward ) ;
-
- void Enable() ;
- void deEnable() ;
- void Stop() ;
- private:
- int x_i4 ;
- int x_i3 ;
- int x_i2 ;
- int x_i1 ;
-
- int x_EA ;
- int x_EB ;
-
- int fase ;
- float position_x ;
- float mDelay ;
- float mMinDelay ;
- float mMaxVelocity ;
- float mVelocity ;
- boolean mDirection ;
- void x1_faseOne() ;
- void x1_faseTwo() ;
- void x2_faseOne() ;
- void x2_faseTwo() ;
- };
-
- #endif
-
- //-----------------
-
- /* Class that contains the variables of a steppermotor
- Should work together with a 'motor-coordinator'-class in case of 'drawing figures' on a plane.
- */
-
- #include "Arduino.h"
- #include "cStepper.h"
-
- cStepper::cStepper( int EA , int EB , int i1 , int i2 , int i3 , int i4 )
- {
- x_i4 = i4 ;
- x_i3 = i3 ;
- x_i2 = i2 ;
- x_i1 = i1 ;
- x_EA = EA ;
- x_EB = EB ;
- pinMode( EA , OUTPUT ) ;
- pinMode( i2 , OUTPUT ) ;
- pinMode( i1 , OUTPUT ) ;
- pinMode( EB , OUTPUT ) ;
- pinMode( i4 , OUTPUT ) ;
- pinMode( i3 , OUTPUT ) ;
-
- deEnable() ;
- Stop() ;
-
- position_x = 0.0f ;
- fase = 0 ;
- mVelocity = 0.0f ; // mVelocity and mDelay are inverse
- mDelay = 1000.0f ;
- mMinDelay = 2.0f ; //in millis. test this out!
- mMaxVelocity = 500.0f ; // in steps pr sec (1000 millis )
-
- mDirection = true ;
- }// end constructor
- //-----------------------------------------
- boolean cStepper::getDirection(){
- return mDirection ;
- }
- void cStepper::setDirection( boolean forward ){
- mDirection = forward ;
- }
- //--------------------------------------------
- void cStepper::setPosition( float start_position )
- { position_x = start_position ; } //at direction-change the local step cannot be reset without disturbing the rythm of the motor
- //the step-situation is monitored by start_position
- float cStepper::getPosition()
- { return position_x ; }
- //---------------------------------------------------------------
-
- void cStepper::setToMaxVelocity(){
- mDelay = mMinDelay ;
- mVelocity = mMaxVelocity ;
- }
- float cStepper::getMaxVelocity(){
- return mMaxVelocity ;
- }
- //velocity in steps pr sec (1000 millis )
- bool cStepper::setVelocity( float velocity ){
- mVelocity = velocity ;
- boolean res = false ;
- if( velocity < mMaxVelocity ){ res = true ; mDelay = 1000/mVelocity ; }
- else{ mDelay = mMinDelay ; }
- return res ;
- }
- //-------------------------------------------------------
-
- void cStepper::setMinDelay( float minDelay ){
- mMinDelay = minDelay ;
- mMaxVelocity = 1000/minDelay ;
- }
- //-------------------------------------------------------
- void cStepper::Step( boolean Forward )// one step at a time!
- {
- if( Forward == true ){ fase +=1 ; position_x += 1 ; }
- else{ fase -=1 ; position_x -= 1 ; }
-
- if( 3 < fase ){ fase = 0 ; }
- if( fase <0 ){ fase = 3 ; }
-
- switch( fase )
- {
- case 0:
- x1_faseOne() ;
- break ;
- case 1:
- x2_faseOne() ;
- break ;
- case 2:
- x1_faseTwo() ;
- break ;
- case 3:
- x2_faseTwo() ;
- break ;
- }// end switch
- delay(mDelay) ; // see arduino for proper expression
- }// end Step
- //-------------------------------
- void cStepper::x1_faseOne()
- {
- digitalWrite( x_i4 , LOW ) ;
- digitalWrite( x_i3 , LOW ) ;
- digitalWrite( x_i1 , LOW ) ;
- digitalWrite( x_i2 , HIGH ) ;
- }//A_faseOne
- //-------------------------------
- void cStepper::x1_faseTwo()
- {
- digitalWrite( x_i4 , LOW ) ;
- digitalWrite( x_i3 , LOW ) ;
- digitalWrite( x_i2 , LOW ) ;
- digitalWrite( x_i1 ,HIGH ) ;
- }//A_faseTwo
- //------------------------------
- void cStepper::x2_faseOne()
- {
- digitalWrite( x_i2 , LOW ) ;
- digitalWrite( x_i1 , LOW ) ;
- digitalWrite( x_i3 , LOW ) ;
- digitalWrite( x_i4 , HIGH ) ;
- }//B_faseOne
- //------------------------------
- void cStepper::x2_faseTwo()
- {
- digitalWrite( x_i2 , LOW ) ;
- digitalWrite( x_i1 , LOW ) ;
- digitalWrite( x_i4 , LOW ) ;
- digitalWrite( x_i3 , HIGH ) ;
- }
- //------------------------------
- void cStepper::Enable(){
- analogWrite( x_EA , 255 ) ;
- analogWrite( x_EB , 255 ) ;
- }
- void cStepper::deEnable(){
- analogWrite( x_EA , 0 ) ;
- analogWrite( x_EB , 0 ) ;
- }
-
- void cStepper::Stop(){
- digitalWrite( x_i1 , LOW ) ;
- digitalWrite( x_i2 , LOW ) ;
- digitalWrite( x_i3 , LOW ) ;
- digitalWrite( x_i4 , LOW ) ;
- }
- //-----------------------------------------------------------------
-
-
-
- #ifndef cPen_h
- #define cPen_h
-
- #include "Arduino.h"
- #include "cStepper.h"
- #include "cPoints.h"
- #include "cPoint.h"
- #include "cArc.h"
-
- class cPen{
- public:
- cPen(cStepper EastWest, cStepper NorthSouth) ;
- cStepper ewX ;
- cStepper nsZ ;
-
- void ReSet() ;
- void goToLinear( cPoint destination ) ;
- void moveLinear( float x , float z ) ;
- void drawPoints( cPoints pts ) ;
- void drawArc(cArc bue) ;
- cPoint getPosition() ;
- private:
- float mMaxVelocity ;
- cPoint mPosition ;
- float pi ;
- float sinFragX( int angle , float xRadius , float zRadius ) ;
- cPoint divide( int arc_angle , float xRadius , float zRadius ) ;
- cPoints buildArc( cArc Arc ) ;
- } ; //end class cPen
-
- #endif
-
- //---------
-
- #include "Arduino.h"
- #include "cStepper.h"
- #include "cPen.h"
- #include "cPoint.h"
- #include "cPoints.h"
- #include "cArc.h"
-
- cPen::cPen( cStepper EastWest , cStepper NorthSouth )
- {
- ewX = EastWest ;
- nsZ = NorthSouth ;
- float xM = ewX.getMaxVelocity() ;
- float zM = nsZ.getMaxVelocity() ;
- if(zM<xM){ this->mMaxVelocity = zM ; }//the slowest motor sets the pace
- else{ this->mMaxVelocity = xM ; }
- mPosition = new cPoint( 0.0f , 0.0f , 0.0f ) ;
- pi = 3.14159 ;
- }// end Constructor
-
- void cPen::ReSet(){
- ewX.setPosition( 0.0f ) ;
- nsZ.setPosition( 0.0f ) ;
- mPosition.x = 0.0f ;
- mPosition.y = 0.0f ;
- mPosition.z = 0.0f ;
- }
-
- cPoint cPen::getPosition(){
- return mPosition ;
- }
-
- void cPen::goToLinear( cPoint destination ){
- moveLinear( destination.x - mPosition.x , destination.y - mPosition.y , destination.z - mPosition.z ) ;
- }
- //---------------------------------------------------------------------------
- void cPen::drawArc(cArc bue){
- cPoints points = this->buildArc(bue) ;
- drawPoints( points ) ;
- }// end ::drawArc
- //---------------------------------
- cPoints cPen::buildArc( cArc Arc ){
- cPoints myPts = new cPoints(Arc.endAngle-Arc.startAngle) ;
- cPoint pt ;
- int ctr = 0 ;
- switch(Arc.clockwise){
- case false :
- for( int i = Arc.startAngle ; i<Arc.endAngle ; i++ ){
- pt = this->divide(i,Arc.xRadius,Arc.zRadius) ;
- myPts.Add(pt) ; //= pt ; //myP[ctr] = pt ;
- ctr++ ;
- }
- break;
- case true :
- for( int i = Arc.startAngle ; i<Arc.endAngle ; i++ ){
- pt = this->divide(360-i,Arc.xRadius,Arc.zRadius) ;
- myPts.Add(pt) ;
- ctr++ ;
- }
- break;
- }// end switch
- return myPts ;
- }// end cPen::buildArc
- //--------------------------
- float cPen::sinFragX( int angle , float xRadius , float zRadius ){
- double px = pow(xRadius,2) ;
- double pz = pow(zRadius,2) ;
- double div = sin(angle*pi/180)/cos(angle*pi/180) ;
- double div2 = (pz + px(pow(div,2)) ;
- double div3 = xRadius*zRadius*sqrt(1/div2) ;
- return float(div3) ;
- }// end sinFragX
- //-------------------------
- cPoint cPen::divide( int arc_angle , float xRadius , float zRadius ){
- cPoint pRes = new cPoint ;
- float frgX = 0.0 ;
- float div = 0.0 ; //sin(arc_angle )/cos(arc_angle ) ;
-
- switch( arc_angle ){
- case <=89 :
- if( 1<=arc_angle ){
- div = sin(arc_angle*pi/180 )/cos(arc_angle*pi/180 ) ;
- frgX = sinFragX(arc_angle , xRadius ,zRadius) ;
- pRes.x=frgX ;
- pRes.z=frgX*div ;
- return pRes ;
- }
- else{
- pRes.x = xRadius ;
- pRes.z = 0 ;
- return pRes ;
- } //betwen 0 and 1
- break;
- case >89 :
- if( 89<arc_angle && arc_angle<91 ){
- pRes.x = 0.0 ;
- pRes.z = zRadius ;
- return pRes ;
- }
- //break ;
- case >=91 :
- if( 92>=arc_angle && arc_angle<=179 ){
- div = sin(arc_angle*pi/180 )/cos(arc_angle*pi/180 ) ;
- frgX = sinFragX(arc_angle , xRadius ,zRadius) ;
- pRes.x=frgX ;
- pRes.z=frgX*div ;
- return pRes ;
- }
- else if( 179>arc_angle && arc_angle<181 ){
- pRes.x = -xRadius ;
- pRes.z = 0.0 ;
- return pRes ;
- }
- //break;
- case >= 181 :
- if( 181>=arc_angle && arc_angle<=269 ){
- div = sin(arc_angle*pi/180 )/cos(arc_angle*pi/180 ) ;
- frgX = sinFragX(arc_angle , xRadius ,zRadius) ;
- pRes.x=frgX ;
- pRes.z=frgX*div ;
- return pRes ;
- }
- else if (269>arc_angle && arc_angle<271 ){
- pRes.x = 0.0 ;
- pRes.z = -zRadius ;
- return pRes ;
- }
- //break;
- case >= 271 :
- if( 271>=arc_angle && arc_angle<=359 ){
- div = sin(arc_angle*pi/180 )/cos(arc_angle*pi/180 ) ;
- frgX = sinFragX(arc_angle , xRadius ,zRadius) ;
- pRes.x=frgX ;
- pRes.z=frgX*div ;
- return pRes ;
- }
- else if( 359>arc_angle && arc_angle<=360){
- pRes.x = xRadius ;
- pRes.z = 0.0 ;
- return pRes ;
- }
- //break;
- }// end switch
- }// end divide
- //---------------------------------------------------------------------------
- void cPen::drawPoints( cPoints pts ){
- // starts painting at current position void cPen::drawPoints( cPoint[] points , int arrayLength )
- cPoint strt ;
- cPoint end ;
- int len = pts.getSize() ;
- for(int i=0; i<len -1 ; i++){
- strt = pts(i) ;
- end = pts(i+1) ;
- moveLinear(end.x - strt.x , end.z - strt.z ) ;
- }// end for
- }// end cPen::drawPoints
-
- //----------------------------
- void cPen::moveLinear( float x , float z ){
- float xVel , zVel ;
- if(abs(x)<abs(z)){
- xVel = 1000*abs(x)/abs(z) ;
- zVel = mMaxVelocity ;
- }
- else{
- //fraction = abs(z)/abs(x) ;
- zVel = 1000*abs(z)/abs(x) ;
- xVel = mMaxVelocity ;
- }
- boolean forwX = false ;
- boolean forwZ = false ;
- //both neg:
- if( x<0 && z<0 ){}
- //both pos:
- else if( 0<=x && 0<=z ){
- forwX = true ;
- forwZ = true ;
- }
- // mixed:
- else{
- if(z<x){
- forwX = true ;
- }
- else{
- forwZ = true ;
- }
- // if(abs(x)<abs(z)){mMax = z ; mMin = x ;}
- //else{ mMin = z ; mMax = x ;}
- }
- ewX.setVelocity( zVel ) ;
- ewX.setDirection(forwX) ;
- nsZ.setVelocity( xVel ) ;
- nsZ.setDirecton(forwZ) ;
- }// end cPen::moveLinear
- //----------------------------------------------------------------
-
-
-
-
- #ifndef cPoints_h
- #define cPoints_h
-
- #include "Arduino.h"
- #include "cPoint.h"
-
- //#pragma once
-
- class cPoints
- {
- public:
- cPoints(int size);
- int getSize() ;
- void Add( cPoint p ) ;
- cPoint getPoint( int AtIndex ) ;
- private:
- cPoint mPoints[];
- int mSize ;
- int incrementor ;
- };
- #endif
-
- //----------
-
-
- #include "Arduino.h"
- #include "cPoints.h"
- #include "cPoint.h"
-
-
- cPoints::cPoints(int size)
- {
- mSize = size ;
- incrementor = 0 ;
- mPoints[size] ;
- }//end constructor
-
- int cPoints::getSize(){
- return mSize ;
- }
-
- void cPoints::Add( cPoint p ){
- mPoints[incrementor] = p ;
- incrementor++ ;
- }
-
- cPoint cPoints::getPoint( int index )
- {
- return mPoints[index] ;
- }
Det er ikke al koden der er med, men der er rigeligt at kigge på. Nogle funktioner er ret uskønne, men lige nu er det syntax og nogle overordnede ting der skal på plads.
Jeg har prøvet at undgå direkte kontakt med Arrays og lavet en 'wrapper' .. og jeg er helt sneget udenom referencer og pointers.