2016-09-14 13:33:11 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
2016-10-18 17:02:33 -06:00
|
|
|
* Copyright (c) 2014-2016 Intel Corporation.
|
2016-09-14 13:33:11 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2016-09-14 13:33:11 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-09-14 13:33:11 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-09-14 13:33:11 -07:00
|
|
|
#include "md.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2016-09-14 13:33:11 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2016-09-14 13:33:11 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate an I2C Motor Driver on I2C bus 0
|
|
|
|
|
|
|
|
upm::MD motors(MD_I2C_BUS, MD_DEFAULT_I2C_ADDR);
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// set direction to CW and set speed to 50%
|
|
|
|
cout << "Spin M1 and M2 at half speed for 3 seconds" << endl;
|
|
|
|
motors.setMotorDirections(MD_DIR_CW, MD_DIR_CW);
|
|
|
|
motors.setMotorSpeeds(127, 127);
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(3);
|
|
|
|
// counter clockwise
|
|
|
|
cout << "Reversing M1 and M2 for 3 seconds" << endl;
|
|
|
|
motors.setMotorDirections(MD_DIR_CCW, MD_DIR_CCW);
|
|
|
|
upm_delay(3);
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Stopping motors" << endl;
|
|
|
|
motors.setMotorSpeeds(0, 0);
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2016-09-14 13:33:11 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2016-09-14 13:33:11 -07:00
|
|
|
}
|