Skip to content

Support Nano motor carrier and update PID behaviour #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/Flasher/Flasher.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
STANDALONE FIRMWARE UPDATE FOR MKR Motor Shiuld
STANDALONE FIRMWARE UPDATE FOR Arduino Motor Carrier

To generate a new firmware, compile D11-Firmware with target MKRMotorShield, 4KB bootloader, LTO enabled, pinmap complete
and execute
Expand All @@ -8,9 +8,14 @@
*/

#include "Wire.h"
#include "fw.h"
#include "ArduinoMotorCarrier.h"

#ifdef ARDUINO_SAMD_NANO_33_IOT
#include "fw_nano.h"
#else
#include "fw_mkr.h"
#endif

#define I2C_ADDRESS 0x09

void setDataRunning(int cmd, uint8_t target, int data) {
Expand Down Expand Up @@ -52,6 +57,9 @@ void setup() {
Serial.println("Reset D11");
setDataRunning(RESET, 0, 0);
delay(10);
} else {
// TODO: on NanoMotorCarrier we have the change to forcefully reset the D11; do it now if it is unresponsive

}

// reset running D11
Expand Down
967 changes: 0 additions & 967 deletions examples/Flasher/fw.h

This file was deleted.

958 changes: 958 additions & 0 deletions examples/Flasher/fw_mkr.h

Large diffs are not rendered by default.

958 changes: 958 additions & 0 deletions examples/Flasher/fw_nano.h

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions examples/Nano/DCMotorTest/DCMotorTest.ino
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);
}
63 changes: 63 additions & 0 deletions examples/Nano/EncoderTest/EncoderTest.ino
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);
}
89 changes: 89 additions & 0 deletions examples/Nano/IMU_Test/IMU_Test.ino
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
}
}
Loading