Commit 91a30eab authored by philip's avatar philip
Browse files

motors working

parent bc519a5a
......@@ -42,16 +42,23 @@ void AggregatMotor::set(float pos)
{
// Guard
if (pos < 0.0) {
printf("pos out of range: %f\n", pos);
printf("pos out of range: %d\n", (int)(100*pos));
pos = 0.0;
} else if (pos > 1.0) {
printf("pos out of range: %f\n", pos);
printf("pos out of range: %d\n", (int)(100*pos));
pos = 1.0;
}
m_pulsewidth_usec_current = pos * (m_pulsewidth_usec_max - m_pulsewidth_usec_min) + m_pulsewidth_usec_min;
int newval = pos * (m_pulsewidth_usec_max - m_pulsewidth_usec_min) + m_pulsewidth_usec_min;
// printf("pw %d", pw);
// don't update if previous value was identical
if (newval == m_pulsewidth_usec_current){
return;
}
m_pulsewidth_usec_current = newval;
// printf("usec_pos %d\n", m_pulsewidth_usec_current);
m_pwm.pulsewidth_us(m_pulsewidth_usec_current);
}
......@@ -69,6 +76,7 @@ void AggregatMotor::suspend()
void AggregatMotor::resume()
{
m_pwm.resume();
m_pwm.pulsewidth_us(m_pulsewidth_usec_current);
}
// void AggregatMotor::run()
......
......@@ -35,11 +35,25 @@ Name | Pins | Description | Use?
UsbLed | 1 | Is USBMIDI connected? Blink on activity? |
EthLed | 1 | Is Ethernet connected? Blink on activity? |
Channel | 4 | Which MIDI Channel to use (1-16) |
Controller Group | 1 | Which Controller group (1-2?) is used? |
HostId | 2-4 | Which ID is used as part of hostname? |
Forward X to Y | 9 | Enable forwarding of messages from USB/MIDI/NET to USB/MIDI/NET (incl. echo) |
## Pinout
Pin | Description
--- | ---
D11 (PB5) | Motor 1
D10 (PD14)| Motor 2
D9 (PD15) | Motor 3
D6 (PE9) | Motor 4
D5 (PE9) | Motor 5
D3 (PE13) | Motor 6
D36 (PB10)| Motor 7
D35 (PB11)| Motor 8
D33 (PB0) | Reserve
D32 (PA0) | Reserve
## Installation / Flashing
1. Connect the USB cable (programming end / opposite of ethernet plug) to computer.
......
......@@ -24,9 +24,9 @@ bool UsbMidiAggregat::just_reconnected()
bool flag = vbus_flag;
vbus_flag = false;
if (flag){
printf("vbus 1 configured %d\n", configured());
}
// if (flag){
// printf("vbus 1 configured %d\n", configured());
// }
return flag;
}
......
......@@ -4,7 +4,7 @@
// default value
#define CHANNEL_OFFSET 0
#define CONTROLLER_OFFSET 0
#define CONTROLLER_OFFSET 102
#define ENABLE_SYSTEM_RESET 1
......@@ -14,20 +14,24 @@
// #define MOTOR_REFRESH_RATE_HZ 60
// #define MOTOR_PULSEWIDTH_MIN_USEC 556
// #define MOTOR_PULSEWIDTH_MAX_USEC 2410
#define MOTOR_PULSEWIDTH_MIN_USEC 760
#define MOTOR_PULSEWIDTH_MAX_USEC 2240
#define MOTOR_REFRESH_RATE_HZ 50
#define MOTOR_PULSEWIDTH_MIN_USEC 0
#define MOTOR_PULSEWIDTH_MAX_USEC 20000000
// #define MOTOR_PULSEWIDTH_MIN_USEC 0
// #define MOTOR_PULSEWIDTH_MAX_USEC 20000000
#define MOTOR_COUNT 1
#define MOTOR_COUNT 8
#define MOTOR_1_PIN PWM_OUT // PA_15
#define MOTOR_2_PIN LED2
#define MOTOR_3_PIN LED3
#define MOTOR_4_PIN LED4
#define MOTOR_1_PIN D11
#define MOTOR_2_PIN D10
#define MOTOR_3_PIN D9
#define MOTOR_4_PIN D6
#define MOTOR_5_PIN D5
#define MOTOR_6_PIN D3
#define MOTOR_7_PIN PB_10
#define MOTOR_8_PIN PB_11
/************ USBMIDI ************/
......@@ -44,7 +48,7 @@
/************ MIDI ************/
#define USE_MIDI 1
#define USE_MIDI 0
#define MIDI_TX_PIN PD_5
#define MIDI_RX_PIN PD_6
......
......@@ -106,7 +106,30 @@ Config config = {
volatile bool motors_running = false;
AggregatMotor motors[MOTOR_COUNT] = {
AggregatMotor(MOTOR_1_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC)
#if MOTOR_COUNT > 0
AggregatMotor(MOTOR_1_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 1
AggregatMotor(MOTOR_2_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 2
AggregatMotor(MOTOR_3_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 3
AggregatMotor(MOTOR_4_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 4
AggregatMotor(MOTOR_5_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 5
AggregatMotor(MOTOR_6_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 6
AggregatMotor(MOTOR_7_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC),
#endif
#if MOTOR_COUNT > 7
AggregatMotor(MOTOR_8_PIN, MOTOR_REFRESH_RATE_HZ, MOTOR_PULSEWIDTH_MIN_USEC, MOTOR_PULSEWIDTH_MAX_USEC)
#endif
};
volatile int32_t channel_offset = CHANNEL_OFFSET;
......@@ -248,11 +271,11 @@ void controller_init()
void controller_handle_msg(uint8_t * buffer, size_t length, Source source)
{
printf("CMD (len %d) ", length);
for(int i = 0; i < length; i++){
printf("%02x", buffer[i]);
}
printf("\n");
// printf("CMD (len %d) ", length);
// for(int i = 0; i < length; i++){
// printf("%02x", buffer[i]);
// }
// printf("\n");
#if ENABLE_CONTROLLER_LOGIC == 1
......@@ -292,28 +315,30 @@ void controller_handle_msg(uint8_t * buffer, size_t length, Source source)
// example
if (msg.channel() == channel_offset){
int32_t motori = msg.controller() - controller_offset;
// printf("controller %d\n", motori);
if (0 <= motori && motori < MOTOR_COUNT){
float pos = u7_to_pos(msg.value());
printf("motor[%d] = %d\n", motori, (int)(pos*100));
// printf("motor[%d] = %d\n", motori, (int)(pos*100));
motors[motori] = pos;
}
}
}
// each channel controls a motor starting from channel_offset
if (msg.type() == MIDIMessage::PitchWheelType){
int32_t motori = msg.channel() - channel_offset;
// if (msg.type() == MIDIMessage::PitchWheelType){
// int32_t motori = msg.channel() - channel_offset;
if (0 <= motori && motori < MOTOR_COUNT){
float pos = s14_to_pos(msg.pitch());
motors[motori] = pos;
}
// if (0 <= motori && motori < MOTOR_COUNT){
// float pos = s14_to_pos(msg.pitch());
// motors[motori] = pos;
// }
}
// }
#endif //ENABLE_CONTROLLER_LOGIC == 1
#if USE_USBMIDI
if (source == SourceUsb){
if (usb_to_midi){
midi_tx(buffer, length);
......@@ -322,6 +347,8 @@ void controller_handle_msg(uint8_t * buffer, size_t length, Source source)
netmidi_tx(buffer, length);
}
}
#endif
#if USE_MIDI
if (source == SourceMidi){
if (midi_to_usb){
usbmidi_tx(buffer, length);
......@@ -330,7 +357,8 @@ void controller_handle_msg(uint8_t * buffer, size_t length, Source source)
netmidi_tx(buffer, length);
}
}
#endif
#if USE_NETMIDI
if (source == SourceNet){
if (net_to_usb){
usbmidi_tx(buffer, length);
......@@ -339,6 +367,7 @@ void controller_handle_msg(uint8_t * buffer, size_t length, Source source)
netmidi_tx(buffer, length);
}
}
#endif
}
void controller_handle_nrpn(uint8_t channel, MidiMessage::NRpnType_t type, MidiMessage::NRpnAction_t action, uint16_t controller, uint16_t value, Source source)
......@@ -394,7 +423,7 @@ void usbmidi_run()
if (usbmidi.readable()){
printf("ubsmidi.readable() = %d\n", usbmidi.readable());
// printf("ubsmidi.readable() = %d\n", usbmidi.readable());
// mark activity
// usbmidi_led = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment