'mcp_can' does not name a type -CAN BUS problems

Hello,
Can anyone help me with these errors? Im doing my first can bus based project, which is activating and working cube mars/t-motor ak-60 motor actuators. Ive used this code from a youtube video from skyentific, a great video for these. But i cant get it to work, there's many errors, fixed some of them, of whcih using a different can library (seeed-studio) helped. but ive still alot that remain. not sure if some are still library issues like the 'mcp_can' does not name a type. My apologies if i havent posted this correctly i have tried to follow the formatting instructions but im not sure if its correct still.
thanks
ERRORS first code below

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Nano, ATmega328P"


C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:13:0: warning: "SERIAL" redefined

   #define SERIAL Serial

 

In file included from sketch\AK60_JOYSTICK.ino.cpp:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:54:0: note: this is the location of the previous definition

 #define SERIAL  0x0

 

AK60_JOYSTICK:49:1: error: 'mcp_can' does not name a type

 mcp_can CAN (SPI_CS_PIN);

 ^~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void setup()':

AK60_JOYSTICK:57:17: error: 'CAN' was not declared in this scope

 while (CAN_OK!= CAN.begin(CAN_1000KBPS))

                 ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:57:17: note: suggested alternative: 'NAN'

 while (CAN_OK!= CAN.begin(CAN_1000KBPS))

                 ^~~

                 NAN

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void loop()':

AK60_JOYSTICK:104:3: error: 'EnterMotorMode' was not declared in this scope

   EnterMotorMode();

   ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:104:3: note: suggested alternative: 'ExitMotorMode'

   EnterMotorMode();

   ^~~~~~~~~~~~~~

   ExitMotorMode

AK60_JOYSTICK:114:21: error: 'CAN' was not declared in this scope

 if (CAN_MSGAVAIL == CAN.checkReceive())

                     ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:114:21: note: suggested alternative: 'NAN'

 if (CAN_MSGAVAIL == CAN.checkReceive())

                     ^~~

                     NAN

AK60_JOYSTICK:116:3: error: 'unpack_reply' was not declared in this scope

   unpack_reply():

   ^~~~~~~~~~~~

AK60_JOYSTICK:133:24: error: a function-definition is not allowed here before '{' token

  void EnterMotorMode (){

                        ^

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void ExitMotorMode()':

AK60_JOYSTICK:157:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:157:3: note: suggested alternative: 'NAN'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   NAN

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void Zero()':

AK60_JOYSTICK:170:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:170:3: note: suggested alternative: 'NAN'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   NAN

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void pack_cmd()':

AK60_JOYSTICK:182:24: error: 'float_to_uint' was not declared in this scope

   unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);

                        ^~~~~~~~~~~~~

AK60_JOYSTICK:184:44: error: 'kP_MIN' was not declared in this scope

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:184:44: note: suggested alternative: 'KP_MIN'

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

                                            KP_MIN

AK60_JOYSTICK:196:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:196:3: note: suggested alternative: 'NAN'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   NAN

AK60_JOYSTICK:199:20: error: a function-definition is not allowed here before '{' token

 void unpack_reply(){

                    ^

AK60_JOYSTICK:217:72: error: a function-definition is not allowed here before '{' token

 unsigned int float_to_uint(float x, float x_min, float x_max, int bits){

                                                                        ^

AK60_JOYSTICK:230:77: error: a function-definition is not allowed here before '{' token

 float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites){

                                                                             ^

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: At global scope:

AK60_JOYSTICK:248:1: error: expected declaration before '}' token

 }

 ^

exit status 1

'mcp_can' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

}#include <can-serial.h>
#include <mcp2515_can.h>
#include <mcp2515_can_dfs.h>
#include <mcp2518fd_can.h>
#include <mcp2518fd_can_dfs.h>
#include <mcp_can.h>

#include <SPI.h>

#ifdef ARDUINO_SAMD_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif

#define UP A1
#define DOWN A2
#define LEFT A3
#define RIGHT A4
#define CLICK A5

#define LED2 8
#define LED3 7

#define P_MIN -12.5f
#define P_MAX 12.5f
#define V_MIN -65.0f
#define V_MAX 65.0f
#define KP_MIN 0.0f
#define KP_MAX 500.0f
#define KD_MIN 0.0f
#define KD_MAX 5.0f
#define T_MIN -18.0f
#define T_MAX 18.0f

float p_in = 0.0f;
float v_in = 0.0f;
float kp_in = 20.0f;
float kd_in = 1.0f;
float t_in = 0.0f;

float p_out = 0.0f;
float v_out = 0.0f;
float t_out = 0.0f;

const int SPI_CS_PIN = 9;

mcp_can CAN (SPI_CS_PIN);

void setup() {

SERIAL.begin (115200);
delay (1000);
while (CAN_OK != CAN.begin(CAN_1000KBPS))
{
SERIAL.println("CAN BUS shield init fail");
SERIAL.println("INIT CAN BUS SHIELD AGAIN");
delay (100);
}

SERIAL.println ("CAN BUS SHIELD INIT OK");

pinMode (UP, INPUT);
pinMode (DOWN, INPUT);
pinMode (LEFT, INPUT);
pinMode (RIGHT, INPUT);
pinMode (CLICK, INPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);

digitalWrite (UP, HIGH);
digitalWrite (DOWN, HIGH);
digitalWrite (LEFT, HIGH);
digitalWrite (RIGHT, HIGH);
digitalWrite (CLICK, HIGH);

digitalWrite (LED2, LOW);
digitalWrite (LED3, LOW);

}

long previousMillis = 0;

void loop() {
{

float p_step = 0.001;
delay (200);
if (digitalRead(UP) == LOW)
{
  p_in = p_in + p_step;
}

if (digitalRead(DOWN) == LOW)
{
  p_in = p_in - p_step;
}
p_in = constrain(p_in, P_MIN, P_MAX);
if (digitalRead(RIGHT) == LOW)
{
  EnterMotorMode();
  digitalWrite (LED2, HIGH);
}
if (digitalRead (LEFT) == LOW)
{
  ExitMotorMode();
  digitalWrite (LED2, LOW);
}

pack_cmd();
if (CAN_MSGAVAIL == CAN.checkReceive())
{
  unpack_reply():
  }


  SERIAL.print(millis() - previousMillis);
  previousMillis = millis();
  SERIAL.print (" ");
  SERIAL.print (p_in);
  SERIAL.print (" ");
  SERIAL.print (p_out);
  SERIAL.print (" ");
  SERIAL.print (v_out);
  SERIAL.print (" ");
  SERIAL.print (t_out);

}

void EnterMotorMode () {
byte buf[8];
buf[0] = 0xFF;
buf[1] = 0xFF;
buf[2] = 0xFF;
buf[3] = 0xFF;
buf[4] = 0xFF;
buf[5] = 0xFF;
buf[6] = 0xFF;
buf[7] = 0xFC;
CAN.sendMsgBuf(0x01, 0, 8, buf);

}
}

void ExitMotorMode () {
byte buf[8];
buf[0] = 0xFF;
buf[1] = 0xFF;
buf[2] = 0xFF;
buf[3] = 0xFF;
buf[4] = 0xFF;
buf[5] = 0xFF;
buf[6] = 0xFF;
buf[7] = 0xFD;
CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void Zero () {
byte buf[8];
buf[0] = 0xFF;
buf[1] = 0xFF;
buf[2] = 0xFF;
buf[3] = 0xFF;
buf[4] = 0xFF;
buf[5] = 0xFF;
buf[6] = 0xFF;
buf[7] = 0xFE;
CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void pack_cmd() {
byte buf[8];

float p_des = constrain (p_in, P_MIN, P_MAX);
float v_des = constrain (v_in, V_MIN, V_MAX);
float kp = constrain (kp_in, KP_MIN, KP_MAX);
float kd = constrain (kd_in, KD_MIN, KD_MAX);
float t_ff = constrain (t_in, T_MIN, T_MAX);

unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);
unsigned int v_int = float_to_uint (v_des, V_MIN, V_MAX, 12);
unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);
unsigned int kd_int = float_to_uint (kd, KD_MIN, KD_MAX, 12);
unsigned int t_int = float_to_uint (t_ff, T_MIN, T_MAX, 12);

buf[0] = p_int >> 8;
buf[1] = p_int & 0xFF;
buf[2] = v_int >> 4;
buf[3] = ((v_int & 0xF) << 4) | (kp_int >> 8);
buf[4] = kp_int & 0xFF;
buf[5] = kd_int >> 4;
buf[6] = ((kd_int & 0xF) << 4) | (t_int >> 8);
buf[7] = t_int & 0xFF;
CAN.sendMsgBuf(0x01, 0, 8, buf);

void unpack_reply() {
byte len = 0;
byte buf [8];
CAN.readMsgBuf (&len, buf);

unsigned long canId = CAN.getCanId();

unsigned int id = buf[0];
unsigned int p_int = (buf[1] << 8) | buf[2];
unsigned int v_int = (buf[3] << 4) | (buf[4] >> 4);
unsigned int i_int = ((buf[4] & 0xF) << 8) | buf[5];

p_out = uint_to_float(p_int, P_MIN, P_MAX, 16);
v_out = uint_to_float(v_int, V_MIN, V_MAX, 12);
p_out = uint_to_float(t_int, T_MIN, T_MAX, 12);

}

unsigned int float_to_uint(float x, float x_min, float x_max, int bits) {
float span = x_max - x_min;
float offset = x_min;
unsigned int pgg = 0;
if (bits == 12) {
pgg = (unsigned int) ((x - offset) * 4095.0 / span);
}
if (bits == 16) {
pgg = (unsigned int)((x - offset) * 65535.0 / span);
}
return pgg;
}

float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites) {
float span = x_max - x_min;
float offset = x_min;
float pgg = 0;
if (bits == 12) {
pgg = ((float) x_int) * span / 4065.0 + offset;
}
if (bits == 16) {
pgg = ((float)x_int) * span / 65535.0 + offset;
}
return pgg;
}

}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

for a start try changing the above to

MCP_CAN CAN (SPI_CS_PIN);

modify the uploaded code of post #1 to use code tags </> - read post #2 by @UKHeliBob

Thanks, error has changed with that

updated errors

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Nano, ATmega328P"





















C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:14:0: warning: "SERIAL" redefined

 #define SERIAL Serial

 

In file included from sketch\AK60_JOYSTICK.ino.cpp:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:54:0: note: this is the location of the previous definition

 #define SERIAL  0x0

 

AK60_JOYSTICK:50:9: error: cannot declare variable 'CAN' to be of abstract type 'MCP_CAN'

 MCP_CAN CAN (SPI_CS_PIN);

         ^~~

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:55:7: note:   because the following virtual functions are pure within 'MCP_CAN':

 class MCP_CAN

       ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:58:18: note: 	virtual void MCP_CAN::enableTxInterrupt(bool)

     virtual void enableTxInterrupt(bool enable = true) = 0;                             // enable transmit interrupt

                  ^~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:59:18: note: 	virtual void MCP_CAN::reserveTxBuffers(byte)

     virtual void reserveTxBuffers(byte nTxBuf = 0) = 0;

                  ^~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:60:18: note: 	virtual byte MCP_CAN::getLastTxBuffer()

     virtual byte getLastTxBuffer() = 0;

                  ^~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:65:18: note: 	virtual byte MCP_CAN::begin(uint32_t, byte)

     virtual byte begin(uint32_t speedset, const byte clockset) = 0;                     // init can

                  ^~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:66:18: note: 	virtual byte MCP_CAN::init_Mask(byte, byte, long unsigned int)

     virtual byte init_Mask(byte num, byte ext, unsigned long ulData) = 0;               // init Masks

                  ^~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:67:18: note: 	virtual byte MCP_CAN::init_Filt(byte, byte, long unsigned int)

     virtual byte init_Filt(byte num, byte ext, unsigned long ulData) = 0;               // init filters

                  ^~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:68:18: note: 	virtual void MCP_CAN::setSleepWakeup(byte)

     virtual void setSleepWakeup(byte enable) = 0;                                       // Enable or disable the wake up interrupt

                  ^~~~~~~~~~~~~~

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:70:18: note: 	virtual byte MCP_CAN::sleep()

     virtual byte sleep() = 0;                                                           // Put the MCP2515 in sleep mode

                  ^~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:71:18: note: 	virtual byte MCP_CAN::wake()

     virtual byte wake() = 0;                                                            // Wake MCP2515 manually from sleep

                  ^~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:72:18: note: 	virtual byte MCP_CAN::setMode(byte)

     virtual byte setMode(byte opMode) = 0;                                              // Set operational mode

                  ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:73:18: note: 	virtual byte MCP_CAN::getMode()

     virtual byte getMode() = 0;                                                         // Get operational mode

                  ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:74:18: note: 	virtual byte MCP_CAN::checkError(uint8_t*)

     virtual byte checkError(uint8_t* err_ptr = NULL) = 0;                               // if something error

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:77:18: note: 	virtual byte MCP_CAN::checkReceive()

     virtual byte checkReceive(void) = 0;                                                // if something received

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:78:18: note: 	virtual byte MCP_CAN::readMsgBufID(byte, volatile long unsigned int*, volatile byte*, volatile byte*, volatile byte*, volatile byte*)

     virtual byte readMsgBufID(byte status,

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:82:18: note: 	virtual byte MCP_CAN::readMsgBufID(long unsigned int*, byte*, byte*)

     virtual byte readMsgBufID(unsigned long *ID, byte *len, byte *buf) = 0;

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:83:18: note: 	virtual byte MCP_CAN::readMsgBuf(byte*, byte*)

     virtual byte readMsgBuf(byte *len, byte *buf) = 0;

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:91:18: note: 	virtual byte MCP_CAN::trySendMsgBuf(long unsigned int, byte, byte, byte, const byte*, byte)

     virtual byte trySendMsgBuf(unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note: 	virtual byte MCP_CAN::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

     virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note: 	virtual byte MCP_CAN::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

     virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:98:18: note: 	virtual void MCP_CAN::clearBufferTransmitIfFlags(byte)

     virtual void clearBufferTransmitIfFlags(byte flags = 0) = 0;                        // Clear transmit flags according to status

                  ^~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:99:18: note: 	virtual byte MCP_CAN::readRxTxStatus()

     virtual byte readRxTxStatus(void) = 0;                                              // read has something send or received

                  ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:100:18: note: 	virtual byte MCP_CAN::checkClearRxStatus(byte*)

     virtual byte checkClearRxStatus(byte *status) = 0;                                  // read and clear and return first found rx status bit

                  ^~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:101:18: note: 	virtual byte MCP_CAN::checkClearTxStatus(byte*, byte)

     virtual byte checkClearTxStatus(byte *status, byte iTxBuf = 0xff) = 0;              // read and clear and return first found or buffer specified tx status bit

                  ^~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:102:18: note: 	virtual bool MCP_CAN::mcpPinMode(byte, byte)

     virtual bool mcpPinMode(const byte pin, const byte mode) = 0;                       // switch supported pins between HiZ, interrupt, output or input

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:103:18: note: 	virtual bool MCP_CAN::mcpDigitalWrite(byte, byte)

     virtual bool mcpDigitalWrite(const byte pin, const byte mode) = 0;                  // write HIGH or LOW to RX0BF/RX1BF

                  ^~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:104:18: note: 	virtual byte MCP_CAN::mcpDigitalRead(byte)

     virtual byte mcpDigitalRead(const byte pin) = 0;                                    // read HIGH or LOW from supported pins

                  ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void setup()':

AK60_JOYSTICK:58:42: error: no matching function for call to 'MCP_CAN::begin(MCP_BITTIME_SETUP)'

   while (CAN_OK != CAN.begin(CAN_1000KBPS))

                                          ^

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:65:18: note: candidate: virtual byte MCP_CAN::begin(uint32_t, byte)

     virtual byte begin(uint32_t speedset, const byte clockset) = 0;                     // init can

                  ^~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:65:18: note:   candidate expects 2 arguments, 1 provided

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void loop()':

AK60_JOYSTICK:105:7: error: 'EnterMotorMode' was not declared in this scope

       EnterMotorMode();

       ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:105:7: note: suggested alternative: 'ExitMotorMode'

       EnterMotorMode();

       ^~~~~~~~~~~~~~

       ExitMotorMode

AK60_JOYSTICK:117:7: error: 'unpack_reply' was not declared in this scope

       unpack_reply():

       ^~~~~~~~~~~~

AK60_JOYSTICK:134:28: error: a function-definition is not allowed here before '{' token

     void EnterMotorMode () {

                            ^

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void ExitMotorMode()':

AK60_JOYSTICK:158:33: error: no matching function for call to 'MCP_CAN::sendMsgBuf(int, int, int, byte [8])'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

                                 ^

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

     virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note:   candidate expects 6 arguments, 4 provided

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

     virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note:   candidate expects 6 arguments, 4 provided

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void Zero()':

AK60_JOYSTICK:171:33: error: no matching function for call to 'MCP_CAN::sendMsgBuf(int, int, int, byte [8])'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

                                 ^

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

     virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note:   candidate expects 6 arguments, 4 provided

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

     virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note:   candidate expects 6 arguments, 4 provided

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void pack_cmd()':

AK60_JOYSTICK:183:24: error: 'float_to_uint' was not declared in this scope

   unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);

                        ^~~~~~~~~~~~~

AK60_JOYSTICK:185:44: error: 'kP_MIN' was not declared in this scope

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:185:44: note: suggested alternative: 'KP_MIN'

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

                                            KP_MIN

AK60_JOYSTICK:197:33: error: no matching function for call to 'MCP_CAN::sendMsgBuf(int, int, int, byte [8])'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

                                 ^

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

     virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note:   candidate expects 6 arguments, 4 provided

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note: candidate: virtual byte MCP_CAN::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

     virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note:   candidate expects 6 arguments, 4 provided

AK60_JOYSTICK:200:23: error: a function-definition is not allowed here before '{' token

   void unpack_reply() {

                       ^

AK60_JOYSTICK:218:75: error: a function-definition is not allowed here before '{' token

   unsigned int float_to_uint(float x, float x_min, float x_max, int bits) {

                                                                           ^

AK60_JOYSTICK:231:80: error: a function-definition is not allowed here before '{' token

   float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites) {

                                                                                ^

exit status 1

cannot declare variable 'CAN' to be of abstract type 'MCP_CAN'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

updated code

[code]

#include <can-serial.h>
#include <mcp2515_can.h>
#include <mcp2515_can_dfs.h>
#include <mcp2518fd_can.h>
#include <mcp2518fd_can_dfs.h>
#include <MCP_CAN.h>

#include <SPI.h>

#ifdef ARDUINO_SAMD_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif

#define UP    A1
#define DOWN  A2
#define LEFT  A3
#define RIGHT A4
#define CLICK A5

#define LED2 8
#define LED3 7

#define P_MIN -12.5f
#define P_MAX  12.5f
#define V_MIN -65.0f
#define V_MAX  65.0f
#define KP_MIN  0.0f
#define KP_MAX 500.0f
#define KD_MIN  0.0f
#define KD_MAX  5.0f
#define T_MIN  -18.0f
#define T_MAX   18.0f


float p_in = 0.0f;
float v_in = 0.0f;
float kp_in = 20.0f;
float kd_in = 1.0f;
float t_in = 0.0f;

float p_out = 0.0f;
float v_out = 0.0f;
float t_out = 0.0f;

const int SPI_CS_PIN = 9;

MCP_CAN CAN (SPI_CS_PIN);



void setup() {

  SERIAL.begin (115200);
  delay (1000);
  while (CAN_OK != CAN.begin(CAN_1000KBPS))
  {
    SERIAL.println("CAN BUS shield init fail");
    SERIAL.println("INIT CAN BUS SHIELD AGAIN");
    delay (100);
  }

  SERIAL.println ("CAN BUS SHIELD INIT OK");

  pinMode (UP, INPUT);
  pinMode (DOWN, INPUT);
  pinMode (LEFT, INPUT);
  pinMode (RIGHT, INPUT);
  pinMode (CLICK, INPUT);
  pinMode (LED2, OUTPUT);
  pinMode (LED3, OUTPUT);

  digitalWrite (UP, HIGH);
  digitalWrite (DOWN, HIGH);
  digitalWrite (LEFT, HIGH);
  digitalWrite (RIGHT, HIGH);
  digitalWrite (CLICK, HIGH);

  digitalWrite (LED2, LOW);
  digitalWrite (LED3, LOW);

}

long previousMillis = 0;

void loop() {
  {

    float p_step = 0.001;
    delay (200);
    if (digitalRead(UP) == LOW)
    {
      p_in = p_in + p_step;
    }

    if (digitalRead(DOWN) == LOW)
    {
      p_in = p_in - p_step;
    }
    p_in = constrain(p_in, P_MIN, P_MAX);
    if (digitalRead(RIGHT) == LOW)
    {
      EnterMotorMode();
      digitalWrite (LED2, HIGH);
    }
    if (digitalRead (LEFT) == LOW)
    {
      ExitMotorMode();
      digitalWrite (LED2, LOW);
    }

    pack_cmd();
    if (CAN_MSGAVAIL == CAN.checkReceive())
    {
      unpack_reply():
      }


      SERIAL.print(millis() - previousMillis);
      previousMillis = millis();
      SERIAL.print (" ");
      SERIAL.print (p_in);
      SERIAL.print (" ");
      SERIAL.print (p_out);
      SERIAL.print (" ");
      SERIAL.print (v_out);
      SERIAL.print (" ");
      SERIAL.print (t_out);

    }

    void EnterMotorMode () {
    byte buf[8];
    buf[0] = 0xFF;
    buf[1] = 0xFF;
    buf[2] = 0xFF;
    buf[3] = 0xFF;
    buf[4] = 0xFF;
    buf[5] = 0xFF;
    buf[6] = 0xFF;
    buf[7] = 0xFC;
    CAN.sendMsgBuf(0x01, 0, 8, buf);
  }
}

void ExitMotorMode () {
  byte buf[8];
  buf[0] = 0xFF;
  buf[1] = 0xFF;
  buf[2] = 0xFF;
  buf[3] = 0xFF;
  buf[4] = 0xFF;
  buf[5] = 0xFF;
  buf[6] = 0xFF;
  buf[7] = 0xFD;
  CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void Zero () {
  byte buf[8];
  buf[0] = 0xFF;
  buf[1] = 0xFF;
  buf[2] = 0xFF;
  buf[3] = 0xFF;
  buf[4] = 0xFF;
  buf[5] = 0xFF;
  buf[6] = 0xFF;
  buf[7] = 0xFE;
  CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void pack_cmd() {
  byte buf[8];

  float p_des = constrain (p_in, P_MIN, P_MAX);
  float v_des = constrain (v_in, V_MIN, V_MAX);
  float kp = constrain (kp_in, KP_MIN, KP_MAX);
  float kd = constrain (kd_in, KD_MIN, KD_MAX);
  float t_ff = constrain (t_in, T_MIN, T_MAX);

  unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);
  unsigned int v_int = float_to_uint (v_des, V_MIN, V_MAX, 12);
  unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);
  unsigned int kd_int = float_to_uint (kd, KD_MIN, KD_MAX, 12);
  unsigned int t_int = float_to_uint (t_ff, T_MIN, T_MAX, 12);

  buf[0] = p_int >> 8;
  buf[1] = p_int & 0xFF;
  buf[2] = v_int >> 4;
  buf[3] = ((v_int & 0xF) << 4) | (kp_int >> 8);
  buf[4] = kp_int & 0xFF;
  buf[5] = kd_int >> 4;
  buf[6] = ((kd_int & 0xF) << 4) | (t_int >> 8);
  buf[7] = t_int & 0xFF;
  CAN.sendMsgBuf(0x01, 0, 8, buf);


  void unpack_reply() {
    byte len = 0;
    byte buf [8];
    CAN.readMsgBuf (&len, buf);

    unsigned long canId = CAN.getCanId();

    unsigned int id = buf[0];
    unsigned int p_int = (buf[1] << 8) | buf[2];
    unsigned int v_int = (buf[3] << 4) | (buf[4] >> 4);
    unsigned int i_int = ((buf[4] & 0xF) << 8) | buf[5];

    p_out = uint_to_float(p_int, P_MIN, P_MAX, 16);
    v_out = uint_to_float(v_int, V_MIN, V_MAX, 12);
    p_out = uint_to_float(t_int, T_MIN, T_MAX, 12);

  }

  unsigned int float_to_uint(float x, float x_min, float x_max, int bits) {
    float span = x_max - x_min;
    float offset = x_min;
    unsigned int pgg = 0;
    if (bits == 12) {
      pgg = (unsigned int) ((x - offset) * 4095.0 / span);
    }
    if (bits == 16) {
      pgg = (unsigned int)((x - offset) * 65535.0 / span);
    }
    return pgg;
  }

  float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites) {
    float span = x_max - x_min;
    float offset = x_min;
    float pgg = 0;
    if (bits == 12) {
      pgg = ((float) x_int) * span / 4065.0 + offset;
    }
    if (bits == 16) {
      pgg = ((float)x_int) * span / 65535.0 + offset;
    }
    return pgg;
  }





}
[/code]

looks as though CAN is not allowed - looking at my code I tend to use

 MCP_CAN CAN0 (SPI_CS_PIN);

update the rest of the code to match

what CAN shield are you using?
have you tested the CAN shield with some of the code in File>Examples>mcp-can, e.g. CAN_loopback ?

its a seeed studio can bus shield, i havent tested it yet ive been trying to get a functioning code first before delving into that side. but i will try look at an example for loop back. i have looked at a check receive example with no luck

think that just altered the error.

error update

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Nano, ATmega328P"





















C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:14:0: warning: "SERIAL" redefined

 #define SERIAL Serial

 

In file included from sketch\AK60_JOYSTICK.ino.cpp:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:54:0: note: this is the location of the previous definition

 #define SERIAL  0x0

 

AK60_JOYSTICK:50:9: error: cannot declare variable 'CAN0' to be of abstract type 'MCP_CAN'

 MCP_CAN CAN0 (SPI_CS_PIN);

         ^~~~

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:55:7: note:   because the following virtual functions are pure within 'MCP_CAN':

 class MCP_CAN

       ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:58:18: note: 	virtual void MCP_CAN::enableTxInterrupt(bool)

     virtual void enableTxInterrupt(bool enable = true) = 0;                             // enable transmit interrupt

                  ^~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:59:18: note: 	virtual void MCP_CAN::reserveTxBuffers(byte)

     virtual void reserveTxBuffers(byte nTxBuf = 0) = 0;

                  ^~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:60:18: note: 	virtual byte MCP_CAN::getLastTxBuffer()

     virtual byte getLastTxBuffer() = 0;

                  ^~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:65:18: note: 	virtual byte MCP_CAN::begin(uint32_t, byte)

     virtual byte begin(uint32_t speedset, const byte clockset) = 0;                     // init can

                  ^~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:66:18: note: 	virtual byte MCP_CAN::init_Mask(byte, byte, long unsigned int)

     virtual byte init_Mask(byte num, byte ext, unsigned long ulData) = 0;               // init Masks

                  ^~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:67:18: note: 	virtual byte MCP_CAN::init_Filt(byte, byte, long unsigned int)

     virtual byte init_Filt(byte num, byte ext, unsigned long ulData) = 0;               // init filters

                  ^~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:68:18: note: 	virtual void MCP_CAN::setSleepWakeup(byte)

     virtual void setSleepWakeup(byte enable) = 0;                                       // Enable or disable the wake up interrupt

                  ^~~~~~~~~~~~~~

In file included from C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/can-serial.h:24:0,

                 from C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:2:

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:70:18: note: 	virtual byte MCP_CAN::sleep()

     virtual byte sleep() = 0;                                                           // Put the MCP2515 in sleep mode

                  ^~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:71:18: note: 	virtual byte MCP_CAN::wake()

     virtual byte wake() = 0;                                                            // Wake MCP2515 manually from sleep

                  ^~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:72:18: note: 	virtual byte MCP_CAN::setMode(byte)

     virtual byte setMode(byte opMode) = 0;                                              // Set operational mode

                  ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:73:18: note: 	virtual byte MCP_CAN::getMode()

     virtual byte getMode() = 0;                                                         // Get operational mode

                  ^~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:74:18: note: 	virtual byte MCP_CAN::checkError(uint8_t*)

     virtual byte checkError(uint8_t* err_ptr = NULL) = 0;                               // if something error

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:77:18: note: 	virtual byte MCP_CAN::checkReceive()

     virtual byte checkReceive(void) = 0;                                                // if something received

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:78:18: note: 	virtual byte MCP_CAN::readMsgBufID(byte, volatile long unsigned int*, volatile byte*, volatile byte*, volatile byte*, volatile byte*)

     virtual byte readMsgBufID(byte status,

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:82:18: note: 	virtual byte MCP_CAN::readMsgBufID(long unsigned int*, byte*, byte*)

     virtual byte readMsgBufID(unsigned long *ID, byte *len, byte *buf) = 0;

                  ^~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:83:18: note: 	virtual byte MCP_CAN::readMsgBuf(byte*, byte*)

     virtual byte readMsgBuf(byte *len, byte *buf) = 0;

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:91:18: note: 	virtual byte MCP_CAN::trySendMsgBuf(long unsigned int, byte, byte, byte, const byte*, byte)

     virtual byte trySendMsgBuf(unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:93:18: note: 	virtual byte MCP_CAN::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

     virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtr,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:95:18: note: 	virtual byte MCP_CAN::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

     virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:98:18: note: 	virtual void MCP_CAN::clearBufferTransmitIfFlags(byte)

     virtual void clearBufferTransmitIfFlags(byte flags = 0) = 0;                        // Clear transmit flags according to status

                  ^~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:99:18: note: 	virtual byte MCP_CAN::readRxTxStatus()

     virtual byte readRxTxStatus(void) = 0;                                              // read has something send or received

                  ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:100:18: note: 	virtual byte MCP_CAN::checkClearRxStatus(byte*)

     virtual byte checkClearRxStatus(byte *status) = 0;                                  // read and clear and return first found rx status bit

                  ^~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:101:18: note: 	virtual byte MCP_CAN::checkClearTxStatus(byte*, byte)

     virtual byte checkClearTxStatus(byte *status, byte iTxBuf = 0xff) = 0;              // read and clear and return first found or buffer specified tx status bit

                  ^~~~~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:102:18: note: 	virtual bool MCP_CAN::mcpPinMode(byte, byte)

     virtual bool mcpPinMode(const byte pin, const byte mode) = 0;                       // switch supported pins between HiZ, interrupt, output or input

                  ^~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:103:18: note: 	virtual bool MCP_CAN::mcpDigitalWrite(byte, byte)

     virtual bool mcpDigitalWrite(const byte pin, const byte mode) = 0;                  // write HIGH or LOW to RX0BF/RX1BF

                  ^~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\libraries\Seeed_Arduino_CAN-2.3.3\src/mcp_can.h:104:18: note: 	virtual byte MCP_CAN::mcpDigitalRead(byte)

     virtual byte mcpDigitalRead(const byte pin) = 0;                                    // read HIGH or LOW from supported pins

                  ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void setup()':

AK60_JOYSTICK:58:20: error: 'CAN' was not declared in this scope

   while (CAN_OK != CAN.begin(CAN_1000KBPS))

                    ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:58:20: note: suggested alternative: 'CAN0'

   while (CAN_OK != CAN.begin(CAN_1000KBPS))

                    ^~~

                    CAN0

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void loop()':

AK60_JOYSTICK:105:7: error: 'EnterMotorMode' was not declared in this scope

       EnterMotorMode();

       ^~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:105:7: note: suggested alternative: 'ExitMotorMode'

       EnterMotorMode();

       ^~~~~~~~~~~~~~

       ExitMotorMode

AK60_JOYSTICK:115:25: error: 'CAN' was not declared in this scope

     if (CAN_MSGAVAIL == CAN.checkReceive())

                         ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:115:25: note: suggested alternative: 'CAN0'

     if (CAN_MSGAVAIL == CAN.checkReceive())

                         ^~~

                         CAN0

AK60_JOYSTICK:117:7: error: 'unpack_reply' was not declared in this scope

       unpack_reply():

       ^~~~~~~~~~~~

AK60_JOYSTICK:134:28: error: a function-definition is not allowed here before '{' token

     void EnterMotorMode () {

                            ^

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void ExitMotorMode()':

AK60_JOYSTICK:158:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:158:3: note: suggested alternative: 'CAN0'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   CAN0

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void Zero()':

AK60_JOYSTICK:171:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:171:3: note: suggested alternative: 'CAN0'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   CAN0

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino: In function 'void pack_cmd()':

AK60_JOYSTICK:183:24: error: 'float_to_uint' was not declared in this scope

   unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);

                        ^~~~~~~~~~~~~

AK60_JOYSTICK:185:44: error: 'kP_MIN' was not declared in this scope

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:185:44: note: suggested alternative: 'KP_MIN'

   unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);

                                            ^~~~~~

                                            KP_MIN

AK60_JOYSTICK:197:3: error: 'CAN' was not declared in this scope

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

C:\Users\user\Documents\Arduino\AK60_JOYSTICK\AK60_JOYSTICK.ino:197:3: note: suggested alternative: 'CAN0'

   CAN.sendMsgBuf(0x01, 0, 8, buf);

   ^~~

   CAN0

AK60_JOYSTICK:200:23: error: a function-definition is not allowed here before '{' token

   void unpack_reply() {

                       ^

AK60_JOYSTICK:218:75: error: a function-definition is not allowed here before '{' token

   unsigned int float_to_uint(float x, float x_min, float x_max, int bits) {

                                                                           ^

AK60_JOYSTICK:231:80: error: a function-definition is not allowed here before '{' token

   float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites) {

                                                                                ^

exit status 1

cannot declare variable 'CAN0' to be of abstract type 'MCP_CAN'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

[code]

#include <can-serial.h>
#include <mcp2515_can.h>
#include <mcp2515_can_dfs.h>
#include <mcp2518fd_can.h>
#include <mcp2518fd_can_dfs.h>
#include <MCP_CAN.h>

#include <SPI.h>

#ifdef ARDUINO_SAMD_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif

#define UP    A1
#define DOWN  A2
#define LEFT  A3
#define RIGHT A4
#define CLICK A5

#define LED2 8
#define LED3 7

#define P_MIN -12.5f
#define P_MAX  12.5f
#define V_MIN -65.0f
#define V_MAX  65.0f
#define KP_MIN  0.0f
#define KP_MAX 500.0f
#define KD_MIN  0.0f
#define KD_MAX  5.0f
#define T_MIN  -18.0f
#define T_MAX   18.0f


float p_in = 0.0f;
float v_in = 0.0f;
float kp_in = 20.0f;
float kd_in = 1.0f;
float t_in = 0.0f;

float p_out = 0.0f;
float v_out = 0.0f;
float t_out = 0.0f;

const int SPI_CS_PIN = 9;

MCP_CAN CAN0 (SPI_CS_PIN);



void setup() {

  SERIAL.begin (115200);
  delay (1000);
  while (CAN_OK != CAN.begin(CAN_1000KBPS))
  {
    SERIAL.println("CAN BUS shield init fail");
    SERIAL.println("INIT CAN BUS SHIELD AGAIN");
    delay (100);
  }

  SERIAL.println ("CAN BUS SHIELD INIT OK");

  pinMode (UP, INPUT);
  pinMode (DOWN, INPUT);
  pinMode (LEFT, INPUT);
  pinMode (RIGHT, INPUT);
  pinMode (CLICK, INPUT);
  pinMode (LED2, OUTPUT);
  pinMode (LED3, OUTPUT);

  digitalWrite (UP, HIGH);
  digitalWrite (DOWN, HIGH);
  digitalWrite (LEFT, HIGH);
  digitalWrite (RIGHT, HIGH);
  digitalWrite (CLICK, HIGH);

  digitalWrite (LED2, LOW);
  digitalWrite (LED3, LOW);

}

long previousMillis = 0;

void loop() {
  {

    float p_step = 0.001;
    delay (200);
    if (digitalRead(UP) == LOW)
    {
      p_in = p_in + p_step;
    }

    if (digitalRead(DOWN) == LOW)
    {
      p_in = p_in - p_step;
    }
    p_in = constrain(p_in, P_MIN, P_MAX);
    if (digitalRead(RIGHT) == LOW)
    {
      EnterMotorMode();
      digitalWrite (LED2, HIGH);
    }
    if (digitalRead (LEFT) == LOW)
    {
      ExitMotorMode();
      digitalWrite (LED2, LOW);
    }

    pack_cmd();
    if (CAN_MSGAVAIL == CAN.checkReceive())
    {
      unpack_reply():
      }


      SERIAL.print(millis() - previousMillis);
      previousMillis = millis();
      SERIAL.print (" ");
      SERIAL.print (p_in);
      SERIAL.print (" ");
      SERIAL.print (p_out);
      SERIAL.print (" ");
      SERIAL.print (v_out);
      SERIAL.print (" ");
      SERIAL.print (t_out);

    }

    void EnterMotorMode () {
    byte buf[8];
    buf[0] = 0xFF;
    buf[1] = 0xFF;
    buf[2] = 0xFF;
    buf[3] = 0xFF;
    buf[4] = 0xFF;
    buf[5] = 0xFF;
    buf[6] = 0xFF;
    buf[7] = 0xFC;
    CAN.sendMsgBuf(0x01, 0, 8, buf);
  }
}

void ExitMotorMode () {
  byte buf[8];
  buf[0] = 0xFF;
  buf[1] = 0xFF;
  buf[2] = 0xFF;
  buf[3] = 0xFF;
  buf[4] = 0xFF;
  buf[5] = 0xFF;
  buf[6] = 0xFF;
  buf[7] = 0xFD;
  CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void Zero () {
  byte buf[8];
  buf[0] = 0xFF;
  buf[1] = 0xFF;
  buf[2] = 0xFF;
  buf[3] = 0xFF;
  buf[4] = 0xFF;
  buf[5] = 0xFF;
  buf[6] = 0xFF;
  buf[7] = 0xFE;
  CAN.sendMsgBuf(0x01, 0, 8, buf);
}

void pack_cmd() {
  byte buf[8];

  float p_des = constrain (p_in, P_MIN, P_MAX);
  float v_des = constrain (v_in, V_MIN, V_MAX);
  float kp = constrain (kp_in, KP_MIN, KP_MAX);
  float kd = constrain (kd_in, KD_MIN, KD_MAX);
  float t_ff = constrain (t_in, T_MIN, T_MAX);

  unsigned int p_int = float_to_uint (p_des, P_MIN, P_MAX, 16);
  unsigned int v_int = float_to_uint (v_des, V_MIN, V_MAX, 12);
  unsigned int kp_int = float_to_uint (kp, kP_MIN, P_MAX, 12);
  unsigned int kd_int = float_to_uint (kd, KD_MIN, KD_MAX, 12);
  unsigned int t_int = float_to_uint (t_ff, T_MIN, T_MAX, 12);

  buf[0] = p_int >> 8;
  buf[1] = p_int & 0xFF;
  buf[2] = v_int >> 4;
  buf[3] = ((v_int & 0xF) << 4) | (kp_int >> 8);
  buf[4] = kp_int & 0xFF;
  buf[5] = kd_int >> 4;
  buf[6] = ((kd_int & 0xF) << 4) | (t_int >> 8);
  buf[7] = t_int & 0xFF;
  CAN.sendMsgBuf(0x01, 0, 8, buf);


  void unpack_reply() {
    byte len = 0;
    byte buf [8];
    CAN.readMsgBuf (&len, buf);

    unsigned long canId = CAN.getCanId();

    unsigned int id = buf[0];
    unsigned int p_int = (buf[1] << 8) | buf[2];
    unsigned int v_int = (buf[3] << 4) | (buf[4] >> 4);
    unsigned int i_int = ((buf[4] & 0xF) << 8) | buf[5];

    p_out = uint_to_float(p_int, P_MIN, P_MAX, 16);
    v_out = uint_to_float(v_int, V_MIN, V_MAX, 12);
    p_out = uint_to_float(t_int, T_MIN, T_MAX, 12);

  }

  unsigned int float_to_uint(float x, float x_min, float x_max, int bits) {
    float span = x_max - x_min;
    float offset = x_min;
    unsigned int pgg = 0;
    if (bits == 12) {
      pgg = (unsigned int) ((x - offset) * 4095.0 / span);
    }
    if (bits == 16) {
      pgg = (unsigned int)((x - offset) * 65535.0 / span);
    }
    return pgg;
  }

  float uint_to_float(unsigned int x_int, float x_min, float x_max, int bites) {
    float span = x_max - x_min;
    float offset = x_min;
    float pgg = 0;
    if (bits == 12) {
      pgg = ((float) x_int) * span / 4065.0 + offset;
    }
    if (bits == 16) {
      pgg = ((float)x_int) * span / 65535.0 + offset;
    }
    return pgg;
  }





}
[/code]

As the error message states, 'MCP_CAN' is a abstract class. Therefore, you can't directly instantiate an object of that type. Take a look in 'mcp_can.h'. You'll see lots of declarations of the form:

virtual void enableTxInterrupt(bool enable = true) = 0; 

These make it a abstract class.

it appears you are attempting to implement a complex program before running basic tests on the target hardware
if I set the Tools> board to Arduino Mega and select File>Examples>mcp-can>CAN_loopback it compiles OK and runs OK

7:58:42.087 -> MCP2515 Initialized Successfully!
17:58:42.087 -> MCP2515 Library Loopback Example...
117:58:43.069 -> Message Sent Successfully!
17:58:43.102 -> Standard ID: 0x100       DLC: 8  Data: 0xAA 0x55 0x01 0x10 0xFF 0x12 0x34 0x56
17:58:43.102 -> Standard ID: 0x100       DLC: 8  Data: 0xAA 0x55 0x01 0x10 0xFF 0x12 0x34 0x56
17:58:43.102 -> Standard ID: 0x100       DLC: 8  Data: 0xAA 0x55 0x01 0x10 0xFF 0x12 0x34 0x56
17:58:43.102 -> Standard ID: 0x100       DLC: 8  Data: 0xAA 0x55 0x01 0x10 0xFF 0x12 0x34 0x56

the code contains the statement

MCP_CAN CAN0(10);                               // Set CS to pin 10

which gives an error in your code

I'm guessing that you and @exo-dynamics are using two different libraries:
https://github.com/Seeed-Studio/Seeed_Arduino_CAN
https://github.com/coryjfowler/MCP_CAN_lib

I am using fowler MCP_CAN_lib

The error messages @exo-dynamics has posted indicate he / she is using https://github.com/Seeed-Studio/Seeed_Arduino_CAN

probably installed one library and been looking at online example code for the other library
I would recommend running examples from the installed library to check they work with the target board
if they fail delete the libarary and instal the other - then run examples

Iam currently trying to use the seeed studio library, i did try the mcp_can fowler library but actually got more errors which the seeed studio lib solved some of. plus its the seeed studio can bus shield im using so thought it would be better in general.

i have tried this but if the codes for an old version of library (due to the yt video being 2 years old) would that cause the problem?

also i understand theres hardware issues that can crop up down the road but shouldnt i be able to compile the code to check it atleast compiles first?

thank you for both of you answering with all of your replies by the way

Then you'll need to write code that's compatible with that library. Start by studying the built-in examples that come with it.

thanks ill get studying on the question of libraries, atleast on initial viewing, the seeed studios lib seems to contain the same fowler mcp_can library, if im right and thats the case, would the age of versions in said libraries make a difference to what code needs to be written specifically or do updated versions not change that?

I don't have time to go through both libraries to see if one was derived from the other or they share a common ancestor. As it stands now, they are different. So, the most straight forward thing to do is pick one and then write you code to be compatible with it.

I have used the fowler MCP_CAN_llib with a number of Canbus shields
your code of post #1 etc appears to be based on this library

as @gfvalvo recommends pick one, run the example programs to check that it works with your shield, if so implement your code based on this library
If the library has problems driving the shield delete it, instal the other library, test and implement

I find it useful to have a USB-CAN dongle which I can attach to a PC to monitor Canbus traffic and test the shields

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.