Java Code, MicroSerial-8 controlled by Modtronics SBC65EC

Hello. I have a little troble with a project at school.
We are supossed to controll a Lynx Robotic Arm with the help of a Modtronix SBC65EC and a Pololu Micro-8 servo controller, and Muvium software.

At first we tried to controll the robot running the Servo controller in Mini SCC 2 mode, but we think some of the servos move too fast and the arm becomes to unstable when it moves verticaly.

We then thought about running it in Pololu mode to slow down the movements. We just used the same code as we used in Mini SCC 2 mode and just changed the bytes sent out to the servo controller. But the only thing that happens is that the green light is flickering and the red light is constantly glowing (on the servo controller).

Can anyone help us with what we are doing wrong? In this example we are trying to slow down servo 0

Code

import com.muvium.UVMRunnable;
import com.muvium.apt.*;

import java.io.*;


public class Pololu extends UVMRunnable implements SerialPortListener
{
	SerialPort 		vcom0;


    
   
    OutputStream out1   ;
   

	/**
	 * Echo the input..!
	 */
	public void serialEvent(SerialPortEvent event){	}


	
	public void run(){
		System.out.println("Starting..");
	
		
	 
        /**
         * Setup COM0
         */
		 vcom0 = getPeripheralFactory().createSerialPort(
								this, 
                                PeripheralFactory.EVENT_PRIORITY_BACKGROUND,
								SerialPort.COM0 |
								SerialPort.IMPLEMENTATION_VIRTUAL |  
								SerialPort.BAUD_2400);
		
	 
        
         vcom0.setOutputBufferSize( 50 );

		try{
		 	vcom0.start();
            
		}catch(PeripheralUnavailableException e){
			System.out.println("Err2");
		}	
		
       
          out1   = vcom0.getOutputStream();
          
          
		
    
		while(true){
            try{

//servo 0

		out1.flush();
		out1.write(128);
		sleep(50);
		out1.write(1);
		sleep(50);
		out1.write(1);
		sleep(50);
		out1.write(0);
		sleep(50);
		out1.write(50);
		sleep(50);

//servo 0	out1.write(128);
		sleep(50);
		out1.write(1);
		sleep(50);
		out1.write(4);
		sleep(50);
		out1.write(0);
		sleep(50);
		out1.write(23);
		sleep(50);
		out1.write(56);
		


		break;		
                
          }catch(Exception e){}
			doEvents();
		}


	}
	
}

Yay robot arms! Sounds like a very fun project.

I’m going to take a stab at the easy answer, did you remember to remove the protocol selection jumper to switch the servo controller into Pololu mode? If not, just yank off that blue jumper (top left corner in the picture, but it’s the only blue jumper) before you power up the controller and don’t look back.

Keep it someplace safe if you decide to switch back to MiniSSC-II mode of course.

Other than that, I haven’t used any of the Modtronix boards, so I can’t completely validate your code, but you already got MiniSSC-II mode working, so you’ve clearly got everything wired right and know how to make the SBC65EC spit out serial bytes.

In terms of format, your code looks correct for Pololu mode, first setting the speed of servo 0 to 50, about 40% of full speed, then commanding it to move to absolute position 3000 (neutral).

I like Pololu mode a lot more for it’s features, particularly speed control, plus you can boost that baud rate and pump out commands much faster (I know, the problem was that it was already going too fast, but still…).

Good luck, and let us know if you have any more ideas or problems (i.e. this doesn’t fix it, or you need help splitting up the position command into high and low bytes).

-Adam

Yes, I have removed the blue jumper. But as I told you, the red light on the servocontroller just keeps on glowing, and the green light is flashing.

The Users guide tells me that this indicates a fatal error, that prevents further operation, so the wiring might be a problem after all? I use the logic-level input for both of the modes. And the program is just the same (just different bytes).

Another problem we had with the Mini SSC 2 mode was that almost 70% of the time the robot just went to 0-position of all the servos and stayed there, even though we could see the program was cycling through. At first we thought that there was a problem with us not having a common ground for all the components, but now that we fixed it, the problem still occurs. We have to restart the microcontroller x-times before the program finally starts. This is very anoying and we are not sure if it is a problem with the hardware or the software. Anyone having any suggestions?

Thanks!!

Yes, you do need common ground between your microcontroller and the servo controller for proper serial communication, good call.

It would be very odd to have MiniSSC-II mode work perfectly, but Pololu mode not work at all, but now that you mention it, those two problems together sound like a startup frame error. I’m assuming that in MiniSSC-II mode, the 30% of the time that you did have servo control, it was just fine until you restarted the system, right?

If you’re turning on your microcontroller board and the servo controller at the same time, say by switching on a common power source, your microcontroller may be sending out that first serial byte before the servo controller has finished its startup routine. I don’t think MiniSSC-II can recover if the servo controller happens to start listening to the serial line in the middle of a packet, which would result in the behavior you’re describing (MiniSSC-II goes to neutral immediately on power on, Pololu mode waits for individual servo commands). You could try adding a delay, say 100 milliseconds, to your microcontroller code before you send out the first packet (or flush the buffer for that matter).

If that’s not it I would ask what your power source/sources are, and if you can rig up a way to look at the actual serial bytes you’re outputting, either by hooking the microcontroller up to a computer serial port through a level shifter, or using an oscilloscope. Hopefully it won’t come to that!

-Adam

I power the servocontroller board from the microcontroller. So you might be correct with your assumptions.

I’ll try to power up the servocontroller from another source later, or maybe try to put a time delay in the code as you mentioned.

But this again does not help me with the trouble I’m having with the Pololu Mode.

I’m sorry I didn’t make this more clear before. I think the behavior you’re seeing are the effects of the same problem in both modes!

In either mode, a startup frame error would be fatal (i.e. would prevent further operation of the servo controller without power-cycling it).

In MiniSSC-II mode, the servos are driven to neutral position as soon as power is turned on, and an immediate frame error would keep further commands from changing the servo positions, which matches the behavior you’re seeing.

In Pololu mode, no signals are sent to an individual servo (i.e. they are left slack) until a serial command has been received for that servo. An immediate frame error would result in the fatal error red light coming on, and no servo motion, also the behavior you’re seeing.

The two modes will have slightly different startup times, and Pololu mode is a little more sensitive to serial errors since it auto-detects an arbitrary baud rate, so it is entirely possible that, without a startup delay, Pololu mode would fail to start up 100% of the time, while MiniSSC-II Mode would fail to start up 70% of the time.

I suspect a startup delay between when you power on the servo controller and when you start sending commands to it would fix the problems you’re having in BOTH Pololu mode and MiniSSC-II mode! There’s no need to power them from a different source, so long as the servos themselves have a sufficient separate power source (unless your microcontroller board can output several amps!).