Invalid Library

Hello everyone. I just recently started using Arduino for a myoelectric arm project. I have been teaching myself how to code, but I found this MotionDemo on GitHub that I am trying to use to help me in my project. When I try to include this library in my project I get an error in compiling. When I tried to include the ZIP file in Arduino it gives me an error message saying the ZIP file doesn’t have a valid library. Can anybody help me? Thanks

robotarm.h (1.89 KB)

When you extract the library from the zip file, you get a folder named:

VarSpeedServo-master

Inside that folder are 5 files, including VarSpeedServo.h, and 1 folder (i.e., Examples).

Go to the folder where you have installed your Arduino IDE. In there, you will see a folder named libraries. Change into that folder and create a new folder named VarSpeedServo, Since my IDE is installed on drive E under the folder named Arduino1.6.9, if I did this, it would look like:

E:/Arduino1.6.9/libraries/VarSpeedServo

Now, go to the folder where you extracted the library files, select everything in that folder (e.g., Examples, keywords.txt, VarSpeedServo.h, etc.), and copy them. Now move to your equivalent of:

E:/Arduino1.6.9/libraries/VarSpeedServo

and copy those 5 files and 1 directory into the VarSpeedServo folder.

You must now close the IDE and restart it for the new library to become available.

Opening the uarm_mouse-master.zip file I get the folder uarm_mouse-master. In this folder there are two files; build.sh and README.md, along with three folders. These folders are lib, mouse, and src. The contents of each are as follows; lib->robotarm->robotarm.cpp, robotarm.h, and VarSpeedServo folder which has both VarSpeedServo.cpp and VarSpeedServo.h. The mouse folder has two files; mouse.pde and sketch.properties. In src there is the MotionDemo.ino fild and Keywords.txt.

After copying the contents of uarm_mouse-master (build.sh, README.md, lib, mouse, and src) into Arduino's library folder, closing the IDE and restarting it, it get the same error message when trying to upload the code along with a new error line of "Invalid library found in /Users/wolf_masterx/Documents/Arduino/libraries/src: /Users/wolf_masterx/Documents/Arduino/libraries/src" along with invalid library found for lib and mouse as well. Thoughts?

If you're not using robotarm.h, which says to include VarSpeedServo.h, why did you list it in your post? Nowhere did you say anything about uarm_mouse-mater.zip. Clearly, you did NOT create a new library directory using the proper library name. Instead, you evidently just copied the files into the libraries directory. Go back and make the proper subdirectory in the libraries directory. It would appear you should have a structure like:

E:/Arduino1.6.9/libraries/uarm_mouse

I apologize for not properly explaining. I am using robotarm.h, which says to include VarSpeedServo.h. In MotionDemo it says <includerobotarm.h>, which I thought is what Arduino was saying is not a valid library as I have used VarSpeedServo.h in other demos and believe it to be working properly.

I have attached the zip file containing everything. I am sorry for the mistake, but as I have tried importing the zip and tried moving the unarchived folder to a subdirectory in Arduino’s libraries, I do not know how to move forward. Any help anyone can give would be a great help. Thanks

uarm_mouse-master.zip (28.3 KB)

Very few people are going to unzip a file they don’t know. If you are using robotarm.cpp, then you need to have a statement in the main file that has:

#include <robotarm.h>

in it. Whatever the “.h” file it, it likely has to be #include’d in the source file if those properties and methods are going to be used in the code.

You’re right, anyone can post things in the forum I didn’t think of that. So in the .cpp file the first line already is
#include <robotarm.h>. In the .h it starts like
#include “VarSpeedServo.h”
#include <Arduino.h>

#ifndef robotarm_h
#define robotarm_h

The VarSpeedServo.h I know is a valid library as I have used it before, but when I tried to go to Sketch → Include Library → Add .ZIP library… to my code for moving the robot, it says the ZIP has no valid library.

This is the code for <robotarm.h> I got from GitHub and the second is <robotarm.cpp>

#include "VarSpeedServo.h"
#include <Arduino.h>

#ifndef robotarm_h
#define robotarm_h

/****************  Macro definitions  ****************/
#define ARM_A                   148    // upper arm
#define ARM_B                   160    // lower arm
#define ARM_2AB                 47360  // 2*A*B
#define ARM_A2                  21904  // A^2
#define ARM_B2                  25600  // B^2
#define ARM_A2B2                47504  // A^2 + B^2

#define ARM_STRETCH_MIN         0
#define ARM_STRETCH_MAX         210
#define ARM_HEIGHT_MIN          -180
#define ARM_HEIGHT_MAX          150
#define ARM_ROTATION_MIN        -90
#define ARM_ROTATION_MAX        90

#define D150A_SERVO_MIN_PUL     700
#define D150A_SERVO_MAX_PUL     2300

#define INIT_POS_L              67
#define MIN_POS_L		10
#define MAX_POS_L		90
#define FIXED_OFFSET_L          5

#define INIT_POS_R              92
#define MIN_POS_R		25
#define MAX_POS_R		150
#define FIXED_OFFSET_R          15

#define INIT_POS_ROT		90
#define MIN_POS_ROT		0
#define MAX_POS_ROT		165
#define FIXED_OFFSET_ROT	0
/*****************  Port definitions  *****************/
#define SERVO_ROT               8     //
#define SERVO_R                 13    //
#define SERVO_L                 10    //
#define MAGNET					2

class robotarm
{
public:
	robotarm();
	void init();    // initialize the uArm position
	void setPosition(double _stretch, double _height, int _armRot); 
	void setAngle(char _servo, double _angle);
	void stabilize();
	int readAngle(char _servo); // angle read = last value given to the servo
	void detachServo(char _servo);
	void getPosition();
	void grab();
	void stop();

private:
	/*****************  Define variables  *****************/
	int heightLst;
	int height;
	int stretch; 
	int rotation; 
	int currentAngle;
	bool magnetON;
	/***************  Create servo objects  ***************/
	VarSpeedServo servoR;
	VarSpeedServo servoL;
	VarSpeedServo servoRot;

};

#endif
#include "robotarm.h"

robotarm::robotarm()
{
	heightLst		= 0;
	height			= 0;
	stretch			= 0;
	rotation		= 0;
}

void robotarm::init()
{
	//define Servo pins
	servoR.attach(SERVO_R,D150A_SERVO_MIN_PUL,D150A_SERVO_MAX_PUL);
	servoL.attach(SERVO_L,D150A_SERVO_MIN_PUL,D150A_SERVO_MAX_PUL);
//	servoRot.attach(SERVO_ROT,D150A_SERVO_MIN_PUL,D150A_SERVO_MAX_PUL);
	pinMode(MAGNET, OUTPUT);
	magnetON=false;
	servoR.stop();
	servoL.stop();
	servoRot.stop();
}

void robotarm::stop()
{
	servoR.stop();
	servoL.stop();
	servoRot.stop();
}
void robotarm::grab()
{
	if (magnetON)
	{
		digitalWrite(MAGNET, LOW);
		magnetON=false;
		Serial.println("Magnet OFF");
	}
	else
	{
		digitalWrite(MAGNET,HIGH);
		magnetON=true;
		Serial.println("Magnet ON");
	}
}
void robotarm::setPosition(double _stretch, double _height, int _armRot)
{
	_armRot = -_armRot;
	// input limit
	_stretch = constrain(_stretch, ARM_STRETCH_MIN,   ARM_STRETCH_MAX)+55;		// +55, set zero -stretch 
	_height  = constrain(_height,  ARM_HEIGHT_MIN,    ARM_HEIGHT_MAX);
	_armRot  = constrain(_armRot,  ARM_ROTATION_MIN,  ARM_ROTATION_MAX) + 90;		// +90, change -90~90 to 0~180
	// angle calculation
	double stretch2height2 = _stretch * _stretch + _height * _height;              // 
	double angleA = (acos( (stretch2height2 - ARM_A2B2) / ARM_2AB )) * RAD_TO_DEG; // angle between the upper and the lower
	double angleB = (atan(_height/_stretch)) * RAD_TO_DEG;                         // 
	double angleC = (acos((ARM_A2 + stretch2height2 -ARM_B2)/(2 * ARM_A * sqrt(stretch2height2)))) * RAD_TO_DEG; // 
	int angleL = angleB + angleC; 
	int angleR = angleA - angleB - angleC;        // 
                      // 
	// angle limit
	angleL = constrain(angleL, MIN_POS_L, MAX_POS_L);
	angleR = constrain(angleR, MIN_POS_R, MAX_POS_R);
	angleR = constrain(angleR, angleL - 90, angleR);	// behind  -120+30 = -90
	if(angleL<15)	angleR = constrain(angleR, 70, angleR);			// front down
	// set servo position
	setAngle(SERVO_R,angleR);
	setAngle(SERVO_L,angleL);
	setAngle(SERVO_ROT,_armRot);

	Serial.print("angleL= ");
	Serial.println(angleL);
	Serial.print("angleR= ");
	Serial.println(angleR);	
	Serial.print("angleRot= ");
	Serial.println(_armRot);	

}

void robotarm::getPosition()
{
	double angleL=(readAngle(SERVO_L))*DEG_TO_RAD;
	double angleR=(readAngle(SERVO_R))*DEG_TO_RAD;
	double angleRot=readAngle(SERVO_ROT);
	double stretch = ARM_A*cos(angleL) + ARM_B*cos(angleR);
	double height = ARM_A*sin(angleL) - ARM_B*sin(angleR);
	Serial.print("current position: (");
	Serial.print(stretch);
	Serial.print(", ");
	Serial.print(height);
	Serial.print(", ");
	Serial.print(angleRot);
	Serial.println(")");
	
}

void robotarm::setAngle(char _servo,double _angle)
{
	switch(_servo)
	{
		case SERVO_L:
			currentAngle=readAngle(SERVO_L);
			_angle = constrain(_angle, MIN_POS_L, MAX_POS_L);
			if( currentAngle < _angle)
			{
				for(int i=currentAngle;i<_angle;i++) 
				{
					servoL.write(i + FIXED_OFFSET_L);
					delay(15);
				}
			}
			else
			{
				for(int i=currentAngle;i>_angle;i--)
				{
					servoL.write(i + FIXED_OFFSET_L);
					delay(15);
				}
			}
			break;
		case SERVO_R:
			currentAngle=readAngle(SERVO_R);
			_angle = constrain(_angle, MIN_POS_R, MAX_POS_R);
			if( currentAngle < _angle)
			{
				for(int i=currentAngle;i<_angle;i++)
				{
					servoR.write(i + FIXED_OFFSET_R);
					delay(15);
				}
			}
			else
			{
				for(int i=currentAngle;i>_angle;i--)
				{
					servoR.write(i + FIXED_OFFSET_R);
					delay(15);
				}
			}
			break;
		case SERVO_ROT:
			_angle = constrain(_angle, MIN_POS_ROT, MAX_POS_ROT);
			currentAngle=readAngle(SERVO_ROT);
			if( currentAngle < _angle)
			{
				for(int i=currentAngle;i<_angle;i++)
				{
					servoRot.write(i + FIXED_OFFSET_ROT);
					delay(15);
				}
			}
			else
			{
				for(int i=currentAngle;i>_angle;i--)
				{
					servoRot.write(i + FIXED_OFFSET_ROT);
					delay(15);
				}
			}
			break;
		default:
			Serial.println("no servo with this name.");
			break;
	}
}

int robotarm::readAngle(char _servo)
{
	switch(_servo)
	{
		case SERVO_L:
			return (servoL.read()-FIXED_OFFSET_L);
		case SERVO_R:
			return (servoR.read()-FIXED_OFFSET_R);
		case SERVO_ROT:
			return servoRot.read();
		default: break;
	}
}

void robotarm::detachServo(char _servo)
{
	switch(_servo)
	{
		case SERVO_L:
			servoL.detach();
			break;
		case SERVO_R:
			servoR.detach();
			break;
		case SERVO_ROT:
			servoRot.detach();
			break;
		default: break;
	}
}

void robotarm::stabilize()
{
	setAngle(SERVO_L,readAngle(SERVO_L));
	setAngle(SERVO_R,readAngle(SERVO_R));
	setAngle(SERVO_ROT,readAngle(SERVO_ROT));
}

nicclayton: You're right, anyone can post things in the forum I didn't think of that.

Just post links to where you downloaded it from instead of just saying "github". Why should I have to go search all over GitHub and hope that I found the same version you are using?

nicclayton: The VarSpeedServo.h I know is a valid library as I have used it before, but when I tried to go to Sketch -> Include Library -> Add .ZIP library.. to my code for moving the robot, it says the ZIP has no valid library.

The problem is not the code, it's that uarm_mouse-master.zip doesn't have the correct folder structure to be installed that way. It's not a library, it's an Arduino sketch, a processing sketch, and a couple of libraries. Unfortunately the author didn't structure it in a way that makes it easy to install and didn't provide any instructions for how to do so. Fortunately for you I'm more considerate so here's the instructions:

  • Unzip uarm_mouse-master.zip
  • move uarm_mouse-master/lib/robotarm/VarSpeedServo to {sketchbook folder}/libraries. To find the location of your sketchbook folder check File > Preferences > Sketchbook location in the Arduino IDE
  • move uarm_mouse-master/lib/robotarm to {sketchbook folder}/libraries.
  • Restart the Arduino IDE if it's running.
  • File > Open > uarm_mouse-master/src/MotionDemo.ino
  • The IDE will ask you if you want to create a folder, click OK

After doing that MotionDemo.ino compiles for me but I can't test if it actually works.

Thank you. It compiles now. Now I just have to create an I2C code to bit bang between and Arduino Uno and a uArm.