Skip to content

Commit

Permalink
Communicate GPMCU with MCMCU to update the motor status bits, which
Browse files Browse the repository at this point in the history
indicate if a given motor is executing a trapezoidal move.
  • Loading branch information
Jonan CM authored and jonancm committed Feb 6, 2014
1 parent d128e95 commit 5906c36
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
65 changes: 65 additions & 0 deletions gpcore/controller_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#endif

#include "controller_status.h"
#include "mctlcom.h"

#include <stdlib.h> // atoi

controller_status_t controller;

Expand Down Expand Up @@ -52,8 +55,70 @@ bool_t motor_is_in_trapezoidal_mode(unsigned char motor)
return condition;
}

void update_motor_status(void)
{
const int size = 64;
char buf[size];
int recvd, status_bit;

mcuicom_send("XA" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_A;
else
controller.motor_status &= ~MOTOR_A;

mcuicom_send("XB" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_B;
else
controller.motor_status &= ~MOTOR_B;

mcuicom_send("XC" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_C;
else
controller.motor_status &= ~MOTOR_C;

mcuicom_send("XD" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_D;
else
controller.motor_status &= ~MOTOR_D;

mcuicom_send("XE" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_E;
else
controller.motor_status &= ~MOTOR_E;

mcuicom_send("XF" CMDEND);
recvd = mctlcom_get_response(buf, size);
buf[recvd] = '\0';
status_bit = atoi(buf);
if (status_bit)
controller.motor_status |= MOTOR_F;
else
controller.motor_status &= ~MOTOR_F;
}

bool_t any_motor_executing_trapezoidal_move(unsigned char motor_flags)
{
update_motor_status();
return controller.motor_status & motor_flags;
}

Expand Down
2 changes: 1 addition & 1 deletion gpcore/controller_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct {
* Bit 1: 1 = Motor B in Trapezoidal move 0 = Motor B not in Trapezoidal move
* Bit 0: 1 = Motor A in Trapezoidal move 0 = Motor A not in Trapezoidal move
*/
char motor_status;
unsigned char motor_status;

/**
* System Configuration.
Expand Down
4 changes: 4 additions & 0 deletions mcuicom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef MCUICOM_H
#define MCUICOM_H

#ifndef CMDEND
#define CMDEND "\r"
#endif

/*****************************************************************************************************
* Serial port timing configuration: 9600 baud *
*****************************************************************************************************/
Expand Down
1 change: 0 additions & 1 deletion motorctl/gpcorecom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "../mcuicom.h"
#include "motor_status.h"
#include "../hostcmdset.h"
#include "pwm.h"
#include "motorctl.h"
#include "../delay.h"
Expand Down

0 comments on commit 5906c36

Please sign in to comment.