-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from arduino-libraries/nano_motor_carrier
Support Nano motor carrier and update PID behaviour
- Loading branch information
Showing
28 changed files
with
3,608 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <ArduinoMotorCarrier.h> | ||
#define INTERRUPT_PIN 6 | ||
|
||
//Variable to store the battery voltage | ||
static int batteryVoltage; | ||
|
||
//Variable to change the motor speed and direction | ||
static int duty = 0; | ||
|
||
void setup() | ||
{ | ||
//Serial port initialization | ||
Serial.begin(115200); | ||
//while (!Serial); | ||
|
||
//Establishing the communication with the motor shield | ||
if (controller.begin()) | ||
{ | ||
Serial.print("MKR Motor Shield connected, firmware version "); | ||
Serial.println(controller.getFWVersion()); | ||
} | ||
else | ||
{ | ||
Serial.println("Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch"); | ||
while (1); | ||
} | ||
|
||
// Reboot the motor controller; brings every value back to default | ||
Serial.println("reboot"); | ||
controller.reboot(); | ||
delay(500); | ||
|
||
int dutyInit = 0; // at 50 it works as espected, at 60 shift sides and is too small duty to move, at 70 is very big duty. | ||
M1.setDuty(dutyInit); | ||
M2.setDuty(dutyInit); | ||
M3.setDuty(dutyInit); | ||
M4.setDuty(dutyInit); | ||
Serial.print("Duty init: "); | ||
Serial.println(dutyInit); | ||
// int duty2 = dutyInit * 16777215 / 100; | ||
// Serial.print("Conversion formula: "); | ||
// Serial.println(duty2); | ||
//while (1); //WHILE 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!! | ||
} | ||
|
||
|
||
void loop() { | ||
|
||
//Take the battery status | ||
//float batteryVoltage = (float)battery.getConverted(); | ||
|
||
//Reset to the default values if the battery level is lower than 11V | ||
// if (batteryVoltage < 11) | ||
// { | ||
// Serial.println(" "); | ||
// Serial.println("WARNING: LOW BATTERY"); | ||
// Serial.println("ALL SYSTEMS DOWN"); | ||
// M1.setDuty(0); | ||
// M2.setDuty(0); | ||
// M3.setDuty(0); | ||
// M4.setDuty(0); | ||
// while (batteryVoltage < 11) | ||
// { | ||
// batteryVoltage = (float)battery.getConverted(); | ||
// } | ||
// } | ||
// else | ||
// { | ||
|
||
//Motor test | ||
for (duty = -100; duty < 100; duty += 1) | ||
{ | ||
Serial.print("Motor Duty: "); | ||
Serial.println(duty); | ||
M1.setDuty(duty); | ||
M2.setDuty(duty); | ||
M3.setDuty(duty); | ||
M4.setDuty(duty); | ||
delay(10); | ||
} | ||
for (duty = 100; duty > -100; duty -= 1) | ||
{ | ||
Serial.print("Motor Duty: "); | ||
Serial.println(duty); | ||
M1.setDuty(duty); | ||
M2.setDuty(duty); | ||
M3.setDuty(duty); | ||
M4.setDuty(duty); | ||
delay(10); | ||
} | ||
|
||
//Keep active the communication MKR1000 & MKRMotorCarrier | ||
//Ping the samd11 | ||
controller.ping(); | ||
//wait | ||
delay(50); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <ArduinoMotorCarrier.h> | ||
#define INTERRUPT_PIN 6 | ||
|
||
//Variable to store the battery voltage | ||
static int batteryVoltage; | ||
|
||
//Variable to change the motor speed and direction | ||
static int duty = 0; | ||
|
||
void setup() | ||
{ | ||
//Establishing the communication with the motor shield | ||
if (controller.begin()) | ||
{ | ||
Serial.print("MKR Motor Shield connected, firmware version "); | ||
Serial.println(controller.getFWVersion()); | ||
} | ||
else | ||
{ | ||
Serial.println("Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch"); | ||
while (1); | ||
} | ||
|
||
//Serial port initialization | ||
Serial.begin(115200); | ||
while (!Serial); | ||
|
||
// Reboot the motor controller; brings every value back to default | ||
Serial.println("reboot"); | ||
controller.reboot(); | ||
delay(500); | ||
|
||
// Reset the encoder internal counter to zero (can be set to any initial value) | ||
Serial.println("reset counters"); | ||
encoder1.resetCounter(0); | ||
encoder2.resetCounter(0); | ||
|
||
M1.setDuty(30); | ||
M2.setDuty(30); | ||
M3.setDuty(30); | ||
M4.setDuty(30); | ||
} | ||
|
||
|
||
void loop() { | ||
|
||
//Chose the encoder to use:encoder1(default) or encoder2 | ||
Serial.print("Encoder1 Pos [counts]: "); | ||
Serial.print(encoder1.getRawCount()); | ||
Serial.print(" Encoder1 vel [counts/sec]: "); | ||
Serial.println(encoder1.getCountPerSecond()); | ||
Serial.print("Encoder2 Pos [counts]: "); | ||
Serial.print(encoder2.getRawCount()); | ||
Serial.print(" Encoder2 vel [counts/sec]: "); | ||
Serial.println(encoder2.getCountPerSecond()); | ||
Serial.println(""); | ||
|
||
//Keep active the communication MKR1000 & MKRMotorCarrier | ||
//Ping the samd11 | ||
controller.ping(); | ||
//wait | ||
delay(50); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
*************************************************************************** | ||
Euler_Streaming.pde - part of sample SW for using BNO055 with Arduino | ||
(C) All rights reserved by ROBERT BOSCH GMBH | ||
Copyright (C) 2014 Bosch Sensortec GmbH | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
**************************************************************************/ | ||
/* Date: 2014/01/07 | ||
Revision: 1.2 | ||
*/ | ||
|
||
#include "BNO055_support.h" //Contains the bridge code between the API and Arduino | ||
#include <Wire.h> | ||
|
||
//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. | ||
// /* bno055 I2C Address */ | ||
// #define BNO055_I2C_ADDR1 0x28 | ||
// #define BNO055_I2C_ADDR2 0x29 | ||
// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 | ||
|
||
//Pin assignments as tested on the Arduino Due. | ||
//Vdd,Vddio : 3.3V | ||
//GND : GND | ||
//SDA/SCL : SDA/SCL | ||
//PSO/PS1 : GND/GND (I2C mode) | ||
|
||
//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) | ||
struct bno055_t myBNO; | ||
struct bno055_euler myEulerData; //Structure to hold the Euler data | ||
|
||
unsigned long lastTime = 0; | ||
|
||
void setup() //This code is executed once | ||
{ | ||
//Initialize I2C communication | ||
Wire.begin(); | ||
|
||
//Initialization of the BNO055 | ||
BNO_Init(&myBNO); //Assigning the structure to hold information about the device | ||
|
||
//Configuration to NDoF mode | ||
bno055_set_operation_mode(OPERATION_MODE_NDOF); | ||
|
||
delay(1); | ||
|
||
//Initialize the Serial Port to view information on the Serial Monitor | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() //This code is looped forever | ||
{ | ||
if ((millis() - lastTime) >= 100) //To stream at 10Hz without using additional timers | ||
{ | ||
lastTime = millis(); | ||
|
||
bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure | ||
|
||
Serial.print("Time Stamp: "); //To read out the Time Stamp | ||
Serial.println(lastTime); | ||
|
||
Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) | ||
Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees | ||
|
||
Serial.print("Roll: "); //To read out the Roll | ||
Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees | ||
|
||
Serial.print("Pitch: "); //To read out the Pitch | ||
Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees | ||
|
||
Serial.println(); //Extra line to differentiate between packets | ||
} | ||
} |
Oops, something went wrong.