Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 5:39910e745cf6
- Parent:
- 4:a5add1353920
--- a/main.cpp Sat Apr 06 09:36:33 2019 +0000
+++ b/main.cpp Sat Apr 06 14:50:41 2019 +0000
@@ -1,7 +1,7 @@
#include "mbed.h"
-#define MOTOR_ENABLE_PIN PA_8
-#define MOTOR_DIR_PIN PA_9
+#define MOTOR_ENABLE_PIN D7
+#define MOTOR_DIR_PIN D8
// Utility
InterruptIn button(USER_BUTTON, PullUp);
@@ -22,18 +22,21 @@
{
motor_enable = 1;
motor_dir = 1;
+ printf("gofwd\r\n");
}
void motor_go_bwd()
{
motor_enable = 1;
motor_dir = 0;
+ printf("gobwd\r\n");
}
void motor_stop()
{
motor_enable = 0;
motor_dir = 0;
+ printf("stop\r\n");
}
void motor_set_home()
@@ -74,7 +77,7 @@
// CAN
Thread canrxa;
-CAN can1(PB_8, PB_9); // RX, TX
+CAN can1(PB_5, PB_6); // RX, TX
CANMessage messageIn;
CANMessage messageOut;
@@ -86,15 +89,16 @@
{
while(1)
{
- if(can1.read(messageIn, filter))
+ if(can1.read(messageIn, filter)&&messageIn.id==0x030)
{
pose = messageIn.data[0] + (messageIn.data[1] << 8) + (messageIn.data[2] << 16) + (messageIn.data[3] << 24);
printf("CAN: mess %d\n\r", pose);
printf("CANaacc: id %x \n\r ",messageIn.id);
- if (pose==1) motor_go_bwd();
if (pose==0) motor_stop();
- if (pose==2) motor_go_fwd();
- else motor_stop();
+ else if (pose==1) motor_go_bwd();
+ else if (pose==2) motor_go_fwd();
+
+ //else motor_stop();
}
wait(0.05);
@@ -107,8 +111,9 @@
int main()
{
+ can1.frequency(125000);
// Motor Initialization
- motor_stop();
+ // motor_stop();
//end0.rise(&end0_int_handler);
//end0.fall(&end0_released);