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.
Dependencies: vnh5019 SerialMultiByte omni_wheel PID jy901 MotorSMLAP PS3
Diff: main.cpp
- Revision:
- 6:6ce8adb328fa
- Parent:
- 5:3eed67b60cd2
- Child:
- 7:4e77a1ae70d1
diff -r 3eed67b60cd2 -r 6ce8adb328fa main.cpp
--- a/main.cpp Sat Dec 07 07:21:50 2019 +0000
+++ b/main.cpp Tue Dec 10 07:29:41 2019 +0000
@@ -3,13 +3,10 @@
#include "math.h"
#include "omni_wheel.h"
#include "motorsmlap.h"
-#include "jy901.h"
#include "SerialMultiByte.h"
-//JY901 jy(PB_9, PB_8); //sda, scl
-
Serial pc(USBTX, USBRX, 115200);
-SerialMultiByte arduino(PC_10,PC_11);
+SerialMultiByte arduinocontroller(PC_10,PC_11);
PwmOut beep(PA_0);
DigitalOut led1(PA_11);
@@ -25,8 +22,9 @@
OmniWheel omni(4);
void setup(){
- arduino.setHeaders(127,127);
- arduino.startReceive(5);
+ arduinocontroller.setHeaders(127,127);
+ arduinocontroller.startReceive(13);
+
omni.wheel[0].setRadian(PII/2.0);
omni.wheel[1].setRadian(7.0/6.0*PII);
omni.wheel[2].setRadian(11.0/6.0*PII);
@@ -70,31 +68,30 @@
int main() {
setup();
float x, y;
- //jy.calibrateAll(50);
- uint8_t weight[5];
+
+ uint8_t button[13];
while (true) {
led2=1;
- arduino.getData(weight);
- for (uint8_t i = 0; i < 4; i++) {
- pc.printf("%d",weight[i]);
+ arduinocontroller.getData(button);
+ for (uint8_t i = 0; i < 13; i++) {
+ pc.printf("%d",button[i]);
pc.printf("\t");
}
-
- y = weight[0] + weight[2] - weight[1] - weight[3];
- x = weight[0] + weight[1] - weight[2] - weight[3];
- if(y < -50){
+
+ if(button[0]==1){
y = -0.5;
- }else if(y > 50){
+ }
+
+ if(button[1]==1){
y = 0.5;
- }else{
- y = 0;
}
- if(x < -50){
+
+ if(button[2]==1){
+ x = 0.5;
+ }
+
+ if(button[3]==1){
x = -0.5;
- }else if(x > 50){
- x = 0.5;
- }else{
- x = 0;
}
omni.computeXY(
@@ -103,22 +100,10 @@
0,
0,
0
- //(pad.getTrigger(0) - pad.getTrigger(1)) / 255.0 * 0.8
);
for(int i=0; i<3; i++){
motor[i].setMotorSpeed(omni.wheel[i].getOutput()*0.8);
}
- if(weight[0]>40 && weight[3]>40){
- for(int i=0; i<3; i++){
- motor[i].setMotorSpeed(0.2);
- }
- }
-
- if(weight[1]>40 && weight[2]>40){
- for(int i=0; i<3; i++){
- motor[i].setMotorSpeed(-0.2);
- }
- }
pc.printf("X = <%f>, Y = <%f>\r\n",x,y);
}
}
\ No newline at end of file